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

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. (...)"


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


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


(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

$ ./ 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 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 Can't exec /bin/sh at 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

but what mere mortal user would think of doing so?


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

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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2018-07-21 19:00 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (450 votes). Check out past polls.