[Chicago-talk] removing line from file.
Wiggins d'Anconia
wiggins at danconia.org
Wed Mar 9 12:07:24 PST 2005
Wiggins d'Anconia wrote:
> Jim Thomason wrote:
>
>>> # ignore first 4 lines
>>> next if 1 .. 4;
>>
>>
>>
>> I believe that should be:
>>
>> next if $. == 1 .. $. == 4;
>>
>> 1..4 won't work, since both 1 and 4 are true values, it never hits the
>> 'next'.
>>
>> -Jim....
>
>
> This is very odd. Your catch seems ok, but the reasoning seems odd.
> C<1..4> is a range, 1 and 4 specifically never enter the picture. And
> regardless the next would *always* get hit rather than 'never' because
> they *are* true. In this case does the 'if' get a list (1,2,3,4), or 4
> (meaning the number in the list) or 4 (the last entry in the range)?? Or
> does it really work where Perl does some magic not looping over the
> range except at each iteration of the outer 'while' (which seems
> impossible)?
Which of course if this was a lesser language it would be, but since it
is Perl it isn't impossible, only difficult ;-).... Checking perldoc
perlop reveals that the range knows its context, and in scalar context
all kinds of fun stuff can occur.... Specifically the original should
work....
http://danconia.org
Not to mention the whole binding order of .. and ==, which
> wouldn't that turn the above into: C<if $. == (1 .. $.) == 4;>, or do I
> have my highest/lowest backwards again?
>
> Of course, we could just opt for the less silly,
>
> next if $. < 5;
>
> :)
>
More information about the Chicago-talk
mailing list