I want to print one hash with one key undefined . I have condition print if key exist . I guess it should not print value for undefined key, but it does .
#!/usr/bin/perl -w
@array = ("abc", 123, "dfg" ,456, "xsd",undef);
%hash = reverse @array;
foreach $k (keys %hash){
print "key $k value $hash{$k}n" if(exists $hash{$k});
}
And another issue is , I want to write one line code for printing hash like below:
print "key $k value $hash{$k}n" foreach $k (keys %hash);
But it fails with error :
syntax error at my_test.pl line 16, near "$k ("
Execution of my_test.pl aborted due to compilation errors.
Please point me where am I wrong?