This doesn't work, because of the (documented in perlop) magic comparison with $. when the conditions are constants:# Get everything between B and D: perl -lwe 'print join " ", grep scalar(/B/../D/), qw(A B C D E F)' # prints: # B C D
Ok, fair enough. But this doesn't work correctly, and there aren't any warnings:# Get everything between up to D: perl -lwe 'print join " ", grep scalar(1../D/), qw(A B C D E F)' # prints: # Use of uninitialized value in range (or flip) at -e line 1. # Use of uninitialized value in range (or flip) at -e line 1. # Use of uninitialized value in range (or flip) at -e line 1. # Use of uninitialized value in range (or flip) at -e line 1. # Use of uninitialized value in range (or flip) at -e line 1. # Use of uninitialized value in range (or flip) at -e line 1.
In fact, as flip-flops return the sequence numbers of their matches, we can double check what these are:# Get everything up to and D: perl -lwe 'print join " ", grep scalar(/./../D/), qw(A B C D E F)' # prints: # A B C D E F
Eh? Why does it start back at 1 after 4E0?# Get everything up to D: perl -lwe 'print join " ", map scalar(/./../D/), qw(A B C D E F)' # prints: # 1 2 3 4E0 1 2
Can anyone shed any light on this? (I'm using Perl 5.8.8 on Ubuntu.)
In reply to Flip-flop won't DWIM by wu-lee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |