Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Never lock $0 inside of a BEGIN block

by grantm (Parson)
on May 21, 2003 at 19:04 UTC ( [id://259842]=note: print w/replies, xml ) Need Help??


in reply to Never lock $0 inside of a BEGIN block

if you flame me on this one be prepared for me to respond with numerous examples where perl says one thing and the truth is completely different. :-)

That sounds like it would be an interesting thread in its own right - why don't you post some examples. Most programming languages are guilty of providing misleading error messages at times, but in my experience Perl messages are some of the more helpful ones. Then again, compared to "An unexpected error has occurred", "segfault" or "Unknown error" pretty much any clue is appreciated.

  • Comment on Re: Never lock $0 inside of a BEGIN block

Replies are listed 'Best First'.
Re: Re: Never lock $0 inside of a BEGIN block
by demerphq (Chancellor) on May 21, 2003 at 20:50 UTC

    Why does

    1 #!perl 2 # Utility vars 3 4 my $foo="Hello there" 5 6 # End utility vars. When do we make these go away? 7 8 ###################################################### 9 # We loop over each character and print them out 10 # this is mostly so that we can do the fnorzle with 11 # boopat over the dulwhup. Which can really pjorn your 12 # noodle 13 14 15 for my $i (0.. length($foo)-1) { 16 print "$i ",substr($foo,$i,1),"\n"; 17 }

    produce the following error

    syntax error at D:\perl\scratch\errors.pl line 15, near "$i (" Execution of D:\perl\scratch\errors.pl aborted due to compilation erro +rs.

    I dont see why this doesn't produce something more intelligent. My general rule for perl errors is that if I don't see the problem immediately on the line that perl tells me I look on the one before, and as the contrived example shows here that can be quite a ways before.

    :-)


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

      Because the following syntax is valid (even if nonsensical):

      my $foo = "Hello there" for (1 .. 3);
      An upshot of the modifier forms of 'for' and 'if' is that you can make C-style static variables with
      sub blah { my $foo if 0; print $foo++,$/; } blah(),blah(),blah();
      Though Larry says it's an accident of implementation that this works...

      --
      [ e d @ h a l l e y . c c ]

        Heh. Ive encountered a bunch of weirdness with using my and modifiers. (I've even argued that it should produce a warning.) I haven't seen the static variable trick. Thats scary. Cool Scary though. :-)

        However I'm still not convinced that this error message couldn't be improved.

        BTW, the static trick only works with if 0; and for (); and thus I still consider it something that should produce a warning.

        # No assignment #With assignment for_blah 0 for_blah 0 for_blah 0 for_blah 0 for_blah 0 for_blah 0 --- --- not_for_blah 0 not_for_blah 0 not_for_blah 1 not_for_blah 1 not_for_blah 2 not_for_blah 2 --- --- if_blah 0 if_blah 1 if_blah 0 if_blah 1 if_blah 0 if_blah 1 --- --- not_if_blah 0 not_if_blah 0 not_if_blah 1 not_if_blah 1 not_if_blah 2 not_if_blah 2 --- ---

        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://259842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-19 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found