in reply to for loops and 'and'
Try this: perl -wne'print for (1..10 or 1..11)' foo where foo is a file with 12 or so lines. You will get "12345678910E0" as the output for the first 10 lines and "1234567891011" as the output for each line thereafter.my $flipflopcount; print for do { my $flipflop; if (!$flipflopcount && $. == 1) { $flipflop = ++$flipflopcount; } if ($flipflopcount && $. == 10) { $flipflop = ++$flipflopcount . "E0"; undef $flipflopcount; } if ($flipflop) { $flipflop; } else { (1.11); } }
To the monk confused by the difference between scalar(1..10) and scalar 1..10, that's a precedence thing. The latter is equivalent to scalar(1)..10 so the scalar() is not forcing .. to have scalar context.
|
|---|