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.

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

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;

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.

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)

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

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


In reply to 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) by Anonymous Monk
in thread Why is the error thrown from close(FH) when the error is the missing <> on while(FH)? by techgrrl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.