Not_a_Number has asked for the wisdom of the Perl Monks concerning the following question:
Not sure how to title this, since I don't know where the issue is. How come this works:
my @ary; while ( <DATA> ) { chomp; push @ary, $_ and next if $_> 5; print; } __DATA__ 3 7 9 1
and not this:
my %hash; while ( <DATA> ) { chomp; $hash{$_}++ and next if $_ > 5; print; } __DATA__ 3 7 9 1
The latter outputs 3791 rather than 31. I know how to get around this; for example I can change the key line to:
$hash{$_}++, next if $_ > 5;I just wonder what the issue is? (BTW I use strict and warnings but get no complaints.)
Thanks, once again, in advance.
dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'and next' question
by sauoq (Abbot) on Oct 26, 2003 at 19:27 UTC | |
by pg (Canon) on Oct 27, 2003 at 01:03 UTC | |
by sauoq (Abbot) on Oct 27, 2003 at 17:03 UTC | |
|
Re: 'and next' question
by Coruscate (Sexton) on Oct 26, 2003 at 18:24 UTC | |
|
Re: 'and next' question
by Anonymous Monk on Oct 26, 2003 at 17:44 UTC | |
by pg (Canon) on Oct 26, 2003 at 20:09 UTC | |
|
Re: 'and next' question
by hanenkamp (Pilgrim) on Oct 26, 2003 at 20:56 UTC | |
by Anonymous Monk on Oct 26, 2003 at 21:51 UTC |