Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
And for the life of me can't figure out what's going on.

Don't worry, you're not the only one who's been bitten by this silly feature (as pointed out by davido).

Another "favorite" one of mine is this (see perlrun):

"If the #! line does not contain the word "perl", the program named after the #! is executed instead of the Perl interpreter. (...)"

<rant>

Let's say you wanted to write a wrapper something like this

#!/bin/sh eval 'PATH=/usr/local/bin:$PATH \ exec perl -x -S $0 "$@"' if 0; #!perl print "this is $^X, version $]\n";

with the idea being that your preferred perl (/usr/local/bin/perl) is being used if found, or else some other (possibly older) one on the default PATH.  Also, you'd like people to be able to call the script via

/path/to/some/other/perl script.pl

so they can directly use whatever perl they have in some non-default location.  Similarly, your Windows users should be allowed to simply say

perl script.pl

(which is why you've put the eval '...' if 0; around the shell code)

The first part works fine, i.e. if you call the script via the shebang/shell wrapper, you'd get as expected

$ ./script.pl this is /usr/local/bin/perl, version 5.012002

but if you try to use some other perl, e.g.

$ /usr/bin/perl -v This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi $ /usr/bin/perl script.pl this is /usr/local/bin/perl, version 5.012002

you still get the same perl version as before!  And even worse, your Windows users would simply get

>perl script.pl Can't exec /bin/sh at script.pl line 1.

Why is that?  Well, Perl tries to be helpful and - as it doesn't see "perl" on the first #! line - calls /bin/sh for you...

Sure, you can make it work by saying

perl -x script.pl

but what mere mortal user would think of doing so?

</rant>


In reply to Re: grep trouble (OT) by Eliya
in thread grep trouble by LogMiner

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2018-11-15 15:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My code is most likely broken because:
















      Results (186 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!