Thats rather clever.... There is a subtle issue with extrapolating that particular idiom though. Suppose we wanted to match lines of exactly four fields, but were only interested in the first two fields of such lines:
dog:cat:pig <== skip, only has three fields
Amy:Ann <== skip, only has two fields
ape:ant:bug:car <== match this line (it has four fields)
but we only need to keep 'ape' and 'ant'
Tweaking the code above, we might think that this will do the trick for us:
while (<DATA>) {
chomp;
(my ($first, $second) = split /:/) == 4 or next;
print "$first $second\n";
}
__DATA__
dog:cat:pig
Amy:Ann
ape:ant:bug:car
However, that doesn't seem to work for us, nothing gets printed. In fact, try as we might, we can't construct any line at all that passes the IDIOM==4 test.
So, does anyone want to guess why IDIOM==4 is so different from IDIOM==2?
Update: As an added hint, testing for IDIOM==3 will match the 'dog:cat:pig' line....
-Blake
|