Perl Flip Flop operator and line numbers -
i noticed while looking @ another question...
if have script this:
while (<>) { print if 5 .. undef; } it skips lines 1..4 prints rest of file. if try this:
my $start_line = 5; while (<>) { print if $start_line .. undef; } it prints line 1. can explain why?
actually i'm not sure why first 1 works.
hmmm looking further found works:
my $start = 5; while (<>) { print if $. == $start .. undef; } so first version magically uses $. line number. don't know why fails variable.
the use of bare number in flip-flop treated test against line count variable, $.. perldoc perlop:
if either operand of scalar
".."constant expression, operand considered true if equal (==) current input line number (the$.variable).
so
print if 5 .. undef; is "shorthand" for:
print if $. == 5 .. undef; the same not true scalar variable not constant expression. why not tested against $..
Comments
Post a Comment