uninitialized error for hash printing

2014-06-22 Thread Sunita Pradhan
I have following code for printing a simple hash. #!/usr/bin/perl -w %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34); foreach $k (keys %hash){ print "key $k:: value $hash{$k}\n"; } It does not print keys and displays following warnings: -- Use of uninitialized value

Re: uninitialized error for hash printing

2014-06-22 Thread John Delacour
On 22 Jun 2014, at 21:01, Sunita Pradhan wrote: > I have following code for printing a simple hash. > > #!/usr/bin/perl -w > %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34); > foreach $k (keys %hash){ > print "key $k:: value $hash{$k}\n"; > } > -- > Use of uninitialized

Re: uninitialized error for hash printing

2014-06-22 Thread Uri Guttman
On 06/22/2014 04:01 PM, Sunita Pradhan wrote: I have following code for printing a simple hash. #!/usr/bin/perl -w %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34); foreach $k (keys %hash){ print "key $k:: value $hash{$k}\n"; } It does not print keys and displays following warn

Re: uninitialized error for hash printing

2014-06-22 Thread Shaji Kalidasan
Hi Sunita, As per Uri's suggestions, here's one way to make it work by surrounding the variable with curly braces [code] %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34); foreach $k (keys %hash){ print "key ${k}:: value $hash{$k}\n"; } [/code] [output] key abc:: value 123 key dfg:: v