Hi.  Newbie to perl here.  I've got two problems (well, two perl-related
problems), relating to the same program.

1. I'm putting together some test programs to try to get down the syntax for
references, etc., but I'm coming across a weird situation I can't figure
out.  I'm setting up a hash of hashes.  For some reason, I'm being told that
a particular variable that I want printed is uninitialized -- but then perl
goes ahead and prints the variable.

Here's the test program, named "referencespractice.pl":

#!/usr/bin/perl -w

my %table = (
        "key1" =>
                {    search        => "alpha",
                    shortname    => "beta",
                },
        "key2" =>
                {    search         => "gamma",
                    shortname    => "delta",
                },
        "key3" =>
                {    search        => "epsilon",
                    shortname    => "whatever",
                },
);

foreach my $keys (%table) {
    print $table{$keys}->{search},"\n";
    print $table{$keys}->{shortname},"\n";
    };

I expect this output:

alpha
beta
gamma
delta
epsilon
whatever

Instead, I get this:

alpha
beta
Use of uninitialized value in print at ./referencespractice.pl line 20.

Use of uninitialized value in print at ./referencespractice.pl line 21.

gamma
delta
Use of uninitialized value in print at ./referencespractice.pl line 20.

Use of uninitialized value in print at ./referencespractice.pl line 21.

epsilon
whatever
Use of uninitialized value in print at ./referencespractice.pl line 20.

Use of uninitialized value in print at ./referencespractice.pl line 21.

(Needless to say, the errors occur within the  two lines in the foreach
loop.)

Camel's description of the error, and undefined variables, didn't clarify
matters for me, and unless I missed something fundamental, the FAQ didn't
have an answer to this conundrum.  I also can't remember, off the top of my
head, the sixth letter of the Greek alphabet, but that's not important right
now.

2. I also don't understand the extra newline I get between each pass of the
foreach loop.  With warnings disabled, the output is as follows:

alpha
beta

gamma
delta

epsilon
whatever

Why are there extra newlines?

Thanks in advance.

 - geoff


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to