in reply to Printing only the "keys that have a value" in hash

Try  if(exists $hash{$key}){...}

Replies are listed 'Best First'.
Re^2: Printing only the "keys that have a value" in hash
by iphone (Beadle) on Nov 01, 2010 at 02:02 UTC

    I have two problems here 1.Hash values are getting printed as array references. 2.I need to print "only the keys and it's corresponding values" if a value is present for the key

    I tried to use your suggestion but getting the following warning exists argument is not a HASH or ARRAY element at orphan_plf.pl line 58

    foreach my $key ( keys %Hash_filematches ) { my $value = {$Hash_filematches{$key}}; print "$key => $value\n" if(exists {$Hash_filematches{$key}}); }