in reply to Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?

My question is: Why is the error not thrown from the while on 83?

It is, it just doesn't say line 83, the line number is wrong, it is a mismatch, example

$ cat junk while( STDIN ){ @ARGV=2; } # 4 # 5 $ perl -w -Mstrict junk Bareword "STDIN" not allowed while "strict subs" in use at junk line 5 +. Execution of junk aborted due to compilation errors.
[download]

$ cat junk while( STDIN ){ @ARGV=2; }
[download]

I vaguely remember when I first learned to always look at the earliest error message, start at the reported line number, and look before, look above -- this is especially true in perl :)

But you've found a new bug in strict.pm, consider

$ cat junk while( STDIN ){ @ARGV=2; } close STDIN;
[download]

With strict the following error message is misleading

$ perl -Mstrict junk Bareword "STDIN" not allowed while "strict subs" in use at junk line 4 +. Execution of junk aborted due to compilation errors.
[download]

If you look at line 4, you'll see  close STDIN , but we know close takes barewords -- it can be very confusing even if you know to look above

But with warnings the error message is more informative

$ perl -w junk Bareword found in conditional at junk line 4. Terminating on signal SIGINT(2)
[download]

Sure, the line number is wrong (and the program runs forever, infinite loop is infinite), but we know  close STDIN; is not a conditional , so there is less confusion

OTOH :) here is where the advantage falls apart , a conditional  close STDIN if fileno STDIN; or  fileno STDIN and close STDIN;

so warnings can detect a bareword in a conditional, strict can name the bareword, strict should say it is in a conditional, its more informative

On the history of the line number bug
Warning gets the line number wrong?
Error messages point to wrong line number in if-elsif construct,
if-elsif weirdness,
No Pause on Elsif in Debugger
https://rt.perl.org/rt3//Public/Search/Simple.html?q=perl5+line+number
#1031: Incorrect line number reporting due to overoptimization
#1034: error line number reported wrong when using here documents
#7084: "Use of uninitialized value" reported on incorrect line number
#8051: -B wrong line number after die
#47632: Undef loop while condition, loop code motion, and bad warning line number? 5.10-RC1 + 5.8.8
#70910: wrong line number in syntax error message
#114070: here-docs cause bogus line numbers
#115768: wrong line number in error message

:) Perl gets the line number right in the beginning (: (see "junk:" below)

$ cat junk while( STDIN ){ @ARGV=@ARGV; } close STDIN ; $ perl -MO=Concise junk h <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 junk:1) v:{ ->3 d <2> leaveloop vK/2 ->e 3 <{> enterloop(next->c last->d redo->4) v ->4 - <@> lineseq vK ->d 4 <;> nextstate(main 1 junk:2) v ->5 b <2> aassign[t6] vKS/COMMON ->c - <1> ex-list lK ->8 5 <0> pushmark s ->6 7 <1> rv2av[t5] lK/1 ->8 6 <#> gv[*ARGV] s ->7 - <1> ex-list lK ->b 8 <0> pushmark s ->9 a <1> rv2av[t3] lKRM*/1 ->b 9 <#> gv[*ARGV] s ->a c <0> unstack v ->4 e <;> nextstate(main 3 junk:4) v:{ ->f g <1> close vK/1 ->h f <#> gv[*STDIN] s ->g junk syntax OK
[download]

update: :) I acknowledge kcott beat me to the punch , I mean he struck first, I mean I'm not a violent person at all, its just an expression, he posted first :p

Comment on Re: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)? ( line number mismatch, look above, look before )(Bareword found in conditional)
Select or Download Code
Replies are listed 'Best First'.
Re^2: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)? ( line number mismatch, look above, look before )(Bareword found in conditional)
by techgrrl (Sexton) on Feb 01, 2013 at 16:44 UTC

    Those are some great links! The first one has some good examples of this occurring in other contexts. I have a lot of reading to do.

    Thanks for taking the time to include those references!

    TechGrrl