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:: value 456
key xsd:: value 34
[/output]
Hope it helps.
On Mon, Jun 23, 2014 at 1:31 AM, Sunita Pradhan <
[email protected]> 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 warnings:
>
> --------------
> Use of uninitialized value $k:: in concatenation (.) or string at
> hash_test2.pl
> line 7.
> key value 34
> Use of uninitialized value $k:: in concatenation (.) or string at
> hash_test2.pl
> line 7.
> key value 123
> Use of uninitialized value $k:: in concatenation (.) or string at
> hash_test2.pl
> line 7.
> key value 456
>
>
> Never happened like this with hash . I am not sure where I am going wrong .
>
>
>
>
>
> -Sunita
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
--
best,
Shaji
----------------------------------------------------------------------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to
God.
----------------------------------------------------------------------------------------------------------------------------------------------