in reply to Flip-flop won't DWIM
This doesn't work, because of the (documented in perlop) magic comparison with $. when the conditions are constants:
Fix:
perl -lwe'$true=1; print for grep $true../D/, qw(A B C D E F)'
Note that it will flip for "E" (like your last version). What you probably intended is:
perl -lwe'my @a=qw(A B C D E F); print for grep ($_==1) .. ($a[$_]=~/D +/), 0..$#a'
Or without a flip-flop:
perl -lwe'for (qw( A B C D E F )) { print; last if /D/ }'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Flip-flop won't DWIM
by wu-lee (Beadle) on May 22, 2009 at 11:05 UTC | |
by ikegami (Patriarch) on May 22, 2009 at 15:11 UTC | |
by Roy Johnson (Monsignor) on May 26, 2009 at 16:22 UTC |