Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: "Can't happen" bugs

by almut (Canon)
on Jan 16, 2007 at 21:06 UTC ( [id://594982]=note: print w/replies, xml ) Need Help??


in reply to "Can't happen" bugs

Not really related to gaal's problem - except for the "Can't be!" part - but I thought I'd share this little episode which happened to me some time ago.

I'd been hacking at the Perl interpreter to create a modified version for a special purpose (details irrelevant here). When I was done, I thought it would be a good idea to rename the binary from "perl" to "plc", to make it clear to me and anyone else that this is not a normal perl. Consequently, I installed this version under /usr/local/plc/..., together with the usual symlink /usr/local/bin/plc pointing to the binary.

To play with this new toy, I had put the shebang line #!/usr/local/bin/plc in my little test script, and the first tests looked good so far. But as my script grew larger, weird things started to happen. Of course, my first thought was "Ok, Almut, you've messed it up!", or at least - with less detrimental effects on my self-esteem - "there's still room for improvement in your initial hacking attempts".

To verify this hypothesis, I quickly went to check whether my test script would still be working as expected when run with the normal (unchanged) Perl. In cases like these, I usually call the desired version explicitly, to avoid having to edit the shebang line. So, I typed - full path to be absolutely sure - /usr/local/bin/perl test_script.pl   Nothing special really. I had done this hundreds of times before, as I usually have several versions of Perl to play with. (Unless you mess with other things, the respective perl binary has no problem finding everything else that belongs to it...)

Somewhat to my surprise, my script's behaviour didn't change. Same weirdness ... Can't be! But after a couple of "Hmm, I could've sworn I'd written code like this before which worked", I then went on to rewrite the problematic code, which wasn't all that difficult, thanks to Perl's TIMTOWTDI. And things were fine again. Until strangeness kept creeping in again and again while doing further tests. At this point, I would've had to seriously question my general Perl coding abilities, so I figured there must be some other explanation... ;)

Well, to make it short, after lots of strace-ing, losing trust in my sanity, etc., I finally found this little paragraph while perusing the output of perldoc perlrun

If the #! line does not contain the word "perl", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.

And my almost infinite ignorance had suddenly been reduced to almost_infinite - 1.

The moral of the story: Thou shalt not dispossess Perl of its proper name, or its wrath and black magic will come down on thee like a ton of bricks :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-19 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found