Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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




  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-13 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found