abdel has asked for the wisdom of the Perl Monks concerning the following question:
hi there, I'm trying to understand the "if" statement used in a loop. what is the different between this two codes?
foreach my $hash ( keys %some ) { if ( $#{ $some{$hash} } >= 1 ) { print $#{ $some{$hash} } . "\n"; } }
the second code.
foreach my $hash ( keys %some ) { next if ( $#{ $some{$hash} } >= 1 ); print $#{ $some{$hash} } . "\n"; }
the first code I get printed the length of the array %some, if it contained 2 element or more. but the second code I get print, if it contain 3 element or more. why is those if-statement not the same output?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: if statement used in foreach-loop?
by BrowserUk (Patriarch) on Dec 10, 2010 at 03:58 UTC | |
|
Re: if statement used in foreach-loop?
by PeterPeiGuo (Hermit) on Dec 10, 2010 at 05:05 UTC | |
|
Re: if statement used in foreach-loop?
by roboticus (Chancellor) on Dec 10, 2010 at 10:20 UTC | |
|
Re: if statement used in foreach-loop?
by JavaFan (Canon) on Dec 10, 2010 at 10:25 UTC |