On 6/1/07, Nath, Alok (STSD) <[EMAIL PROTECTED]> wrote:
 But when decalared this way it gives a warning message :"Use of
uninitialized value in concatenation (.) or string at"

in a print statement which is something like this :

                my %myhash = map { $_ => undef } qw/A B C D E F G H I J
K/;
                foreach my $key (%myhash){
                        print $myhash{$key}
                }

A hash in list context returns a list of keys _and_ values.  You need
to use the keys function to get only the keys.  You also probably want
to sort the keys since they are returned in an unspecified order.
Also, if you don't want undef warnings for values that have not been
set yet then use the empty string instead of undef (this really
depends on what you are planning to do).

my %h  = map { $_ => '' } qw<A B C D E F G H I J K>;

for my $key (sort keys %h) {
   print "$key is [$h{$key}]\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to