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
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
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
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