Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How can I make it only print "pk1" since "pk2" has no value in it, without having to go through second loop. What's wrong with my test above? Now it prints both "pk1 and pk2"#!/usr/bin/perl -w use strict; use Data::Dumper; my $hoh = { 'pk1' => { 'sk1' => [ 'val1', 'val2' ], 'sk2' => { 'tk1' => 'val1 val2 ', 'tk2' => 'val9,val7' }, 'sk3' => 'val10 val11', 'sk4' => 21 }, 'pk2' => {}, }; #print Dumper $hoh; foreach my $k ( keys %{$hoh} ) { if( $hoh->{$k} ) { print "$k\n"; }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing Hash with empty value in HoH
by salva (Canon) on Jun 15, 2005 at 10:16 UTC | |
by Limbic~Region (Chancellor) on Jun 15, 2005 at 12:40 UTC | |
|
Re: Testing Hash with empty value in HoH
by dorward (Curate) on Jun 15, 2005 at 10:18 UTC | |
|
Re: Testing Hash with empty value in HoH
by monkey_boy (Priest) on Jun 15, 2005 at 10:16 UTC |