#!perl ??

Discussion in 'Perl Misc' started by J Krugman, Apr 2, 2005.

  1. J Krugman

    J Krugman Guest

    I've seen code that starts with the line

    #!perl

    but when I try the same thing myself, I get a 'bad interpreter'
    error. And yet, something like this:

    % perl -le 'print "hello"'

    works perfectly. What do I have to do to use #!perl (instead of
    a fully qualified path) as my shebang line?

    TIA!

    jill
    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
     
    J Krugman, Apr 2, 2005
    #1
    1. Advertising

  2. J Krugman

    Tintin Guest

    "J Krugman" <> wrote in message
    news:d2li3q$qte$...
    >
    >
    > I've seen code that starts with the line
    >
    > #!perl


    Which does nothing on Windows systems, or the below error on Unix systems.

    Note, that any perl switches will be recognised on Windows systems.

    >
    > but when I try the same thing myself, I get a 'bad interpreter'
    > error.


    As to be expected on Unix systems. You need to use the absolute path to
    perl.

    >And yet, something like this:
    >
    > % perl -le 'print "hello"'


    The shell searches the directories in the PATH environment variable to find
    where perl is.

    >
    > works perfectly. What do I have to do to use #!perl (instead of
    > a fully qualified path) as my shebang line?


    Either use Windows, or call the script directly with perl, eg:

    perl yourscript.pl
     
    Tintin, Apr 2, 2005
    #2
    1. Advertising

  3. J Krugman <> wrote:
    >
    > I've seen code that starts with the line
    >
    > #!perl



    If run on Windows, you could put command line switches on that
    line and they would be recognized.


    > but when I try the same thing myself, I get a 'bad interpreter'
    > error.



    If run on *nix, you get that error message.


    > What do I have to do to use #!perl (instead of
    > a fully qualified path) as my shebang line?



    Why do you think you want to use #!perl (instead of a fully
    qualified path) as your shebang line?

    That is, what problem are you hoping to overcome by being able
    to do what you've asked?

    If we knew that, we might be able to suggest an alternative.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 2, 2005
    #3
  4. At 2005-04-02 02:37AM, J Krugman <> wrote:
    [...]
    > What do I have to do to use #!perl (instead of
    > a fully qualified path) as my shebang line?


    use the env utility:
    #!/usr/bin/env perl

    unless you also need to use -T in which case use a fully qualified path
    to perl.

    see also http://www.spanner.org/lists/osxperl/2005/02/21/bd5a5153.html

    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Apr 2, 2005
    #4
  5. J Krugman

    J Krugman Guest

    Re: #!perl ??

    In <> Tad McClellan <> writes:

    >J Krugman <> wrote:
    >> What do I have to do to use #!perl (instead of
    >> a fully qualified path) as my shebang line?


    >Why do you think you want to use #!perl (instead of a fully
    >qualified path) as your shebang line?


    It's just laziness on my part :) . I want be able to download Perl
    scripts and run them as is (after changing permissions):

    % wget -q -O perl_script.pl http://url.to.some/perl_script.txt && \
    > chmod +x perl_script.pl && \
    > perl_script.pl


    without having to fuss with firing up vi and fixing the first line.
    (Of course, the above is something I'd do only with a script that
    I was confident was safe.) Arguably I could just use

    % perl perl_script.pl

    but this solution is suboptimal because often a Perl script will
    have switches on the first line that are critical to its operation,
    so I'd have to first inspect that first line and replicate the
    switches in my own invocation. This is a minor pain with simple
    switches like '-l', but it because increasingly more of a pain as
    the complexity of the switches increases.

    As I said, just another case of programmerly laziness...

    jill

    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
     
    J Krugman, Apr 3, 2005
    #5
  6. J Krugman

    Anno Siegel Guest

    Re: #!perl ??

    J Krugman <> wrote in comp.lang.perl.misc:
    > In <> Tad McClellan
    > <> writes:
    > >J Krugman <> wrote:
    > >> What do I have to do to use #!perl (instead of
    > >> a fully qualified path) as my shebang line?


    [...]

    > Arguably I could just use
    >
    > % perl perl_script.pl
    >
    > but this solution is suboptimal because often a Perl script will
    > have switches on the first line that are critical to its operation,


    Perl is friendly enough to parse those switches, even when invoked
    explicitly, so don't worry about that.

    > As I said, just another case of programmerly laziness...


    ....supported by Perl, so just go along with your intuition.

    Anno
     
    Anno Siegel, Apr 3, 2005
    #6
  7. J Krugman

    J Krugman Guest

    Re: #!perl ??

    In <d2pn0h$bth$-Berlin.DE> -berlin.de (Anno Siegel) writes:

    >J Krugman <> wrote in comp.lang.perl.misc:
    >> In <> Tad McClellan
    >> <> writes:
    >> >J Krugman <> wrote:
    >> >> What do I have to do to use #!perl (instead of
    >> >> a fully qualified path) as my shebang line?


    >[...]


    >> Arguably I could just use
    >>
    >> % perl perl_script.pl
    >>
    >> but this solution is suboptimal because often a Perl script will
    >> have switches on the first line that are critical to its operation,


    >Perl is friendly enough to parse those switches, even when invoked
    >explicitly, so don't worry about that.


    >> As I said, just another case of programmerly laziness...


    >...supported by Perl, so just go along with your intuition.


    Thanks!!!

    jill

    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
     
    J Krugman, Apr 4, 2005
    #7
  8. J Krugman

    Ron Savage Guest

    Ron Savage, Apr 5, 2005
    #8
  9. Ron Savage <> wrote in news:20054520293.919522@ron:

    > On Sat, 2 Apr 2005 17:37:30 +1000, J Krugman wrote:


    Did Jill make the comments below? No.

    Please use a more effective quoting style and avoid misattributions.

    > Search this page
    >
    > http://savage.net.au/Perl/html/upgrade-perl-apache.html
    >
    > for /usr/bin/perl and you'll what to do under Windows for the she-bang
    > line.


    1. You completely missed the point of Jill's post.

    2. Her question was not about setting up Apache and Perl on Windows.

    3. Even if it were, the answer you pointed to is not that great. See
    http://httpd.apache.org/docs-2.0/mod/core.html#scriptinterpretersource
    for a better way.


    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Apr 5, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,824
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    310
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    699
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    302
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    702
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page