in reply to problem with foreach
can't possibly work. Unfortunately. See perlsyn:$b ++ if ( $_ eq "b" ) foreach @a ;
Any simple statement may optionally be followed by a SINGLE modifier, just before the terminating semicolon (or block ending).Note the stress on "single". That's what it means.
This will work:
as will this:( $_ eq "b" ) and $b ++ foreach @a ;
foreach(@a) { $b ++ if ( $_ eq "b" ); }
p.s. I think it's not good style to detach the ++ operator from the lvalue it's working on. So, use $b++ instead of $b ++.
And in the
syntax, the parens around the condition are unnecessary.statement if condition;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with foreach
by jeanluca (Deacon) on Jun 16, 2006 at 08:34 UTC | |
by bart (Canon) on Jun 16, 2006 at 08:39 UTC | |
by Jasper (Chaplain) on Jun 16, 2006 at 11:37 UTC |