Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

"perl args" or " args"

by dragonchild (Archbishop)
on Jul 17, 2003 at 20:16 UTC ( #275371=perlmeditation: print w/replies, xml ) Need Help??

I'm curious - do most people put the she-bang line in or call their script as an argument to perl? I prefer the she-bang line, but I've noticed people where I work (in a bank) do the other a lot ...

We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

  • Comment on "perl args" or " args"

Replies are listed 'Best First'.
Re: "perl args" or " args"
by Abigail-II (Bishop) on Jul 17, 2003 at 20:38 UTC
    I always put the she-bang line in, if only because it lets my editor know it's a Perl program. Furthermore, it allows you to put arguments to perl itself there - although since we have 5.6, I don't do it so often anymore. I used to put -w on the shebang line, but now we have lexical warnings. -T still goes there, for the few programs I write that need it. Every now and then I put -l or -p/-n there, but that's fairly uncommon.

    Having said that, even with a she bang line, I sometimes do perl program args. Typically if the program doesn't have the execute bit set yet. Or if I cut-and-pasted a program from perlmonks or comp.lang.perl.misc that doesn't have a she-bang line, or has a she-bang line not pointing to a perl on my machine.


Re: "perl args" or " args"
by sauoq (Abbot) on Jul 17, 2003 at 20:57 UTC

    I always add a shebang line but I often use the perl script args to execute scripts. In particular, it is useful to test a script with multiple versions of perl or different installations¹.

    I work on a variety of machines, some with multiple installations (usually one for general use and occasionally another for something specialized) and I keep a personal installation in my NFS'd home directory.

    "My two cents aren't worth a dime.";
Re: "perl args" or " args" (neither/install)
by tye (Sage) on Jul 18, 2003 at 15:30 UTC


    I consider it a rather large mistake to have a tool that you invoke via either "perl ..." or " ...". I often make improvements to tools that result in them being implemented in different languages. A tool might start out as a shell script or batch file and later become a Perl script and then a compiled executable (sometimes these transition even happen in the other direction). I just want to use the tool, using a descriptive name. I don't want to think about what language it happens to have been implemented in this week.

    And I really don't want to worry about updating a bunch of other tools that make use of that tool just because I decide to change implementation language.

    For me, the *.pl file is the source code for the script. It starts with "#!/usr/bin/perl" plus whatever options the script needs. Then there is the install process that does the follow things on Unix:

    • Remove the ".pl" from its name
    • Move the script to the proper directory in $PATH
    • Change the "/usr/bin/perl" part to the correct path to perl (if on a broken system that doesn't have /usr/bin/perl or perhaps where /usr/bin/perl is the wrong version of Perl).
    • chmod a+x
    On Win32:
    • Run pl2bat (which changes the ".pl" to ".bat")
    • Move the script to the proper directory in %PATH%

                    - tye
      Excellent node! ++!

      Would you mind doing a meditation on Perl installation process, or even just "How I set up a new application environment" ... ? I would love to see the thoughts of some of the monks on the matter ...

      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I don't like dot-slashing something in the current directory to run it. Prepending a perl is just easier - though that might be different if I was a real touchtypist. So by that token should I do the
      #!/bin/sh eval 'exec perl -wS $0 ${1+"$@"}' if 0;

      at the top of my scripts and invoke them all with sh foo? :^)

      PS: Since I've replied to half the original question: my editor puts the shebang line in there for me, so I always have one - unless I'm trying something real quick like, which I do just like jeffa (launch perl, paste, Ctrl-D).

      Makeshifts last the longest.

Re: "perl args" or " args"
by LazerRed (Pilgrim) on Jul 17, 2003 at 20:36 UTC
    I always use the #! line. It's a habit from my sh/csh/ksh scripting days.


      Same here

      MMMMM... Chocolaty Perl Goodness.....

Re: "perl args" or " args"
by Dog and Pony (Priest) on Jul 18, 2003 at 02:01 UTC
    I always put the shebang line, out of habit. I also always, on all platforms, name the file with ".pl" as extension. And I almost always, also on any platform, execute it with "perl".

    All of this is habits I've acquired, for good or for bad. The shebang line is nice to have there, it makes it clear it is a perl script from the start, it makes it easy to move between platforms (usually) or to a web server, and it allows for switches like -w and others. "use warnings" still isn't available everywhere, especially if you are doing a script for someone else to run on a random webhotel somewhere.

    I like the extension aswell, since it tells me what kind of file it is already in the directory list. It has some added benefits with execution on windows, and when dealing with web servers. Some people has lots of arguments against this kind of notation, saying it is a DOS/Windows idea that should be shot on sight - I disagree. Of course it isn't enough metadata for complex handling (lots of people point to Macs here) but it sure is enough for a quick visual check of a directory listing.

    Executing explicitly via the perl program however, well, that is mostly just sillyness, some would probably call it "cargo cult execution" or something. It's a silly habit, it still works the way it should, no harm done except pressing a few keys too many. I do however like that I *know* what I am doing. When I type "perl" I know that I am executing a perl program. If I accidently execute some other file, Perl will just hiccup. I will not start something I don't want to.

    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: "perl args" or " args"
by blue_cowdawg (Monsignor) on Jul 18, 2003 at 02:25 UTC

    I am definitely a fan of the octothorpe bang (shebang) myself. Often times I have folks running scripts that I have written that aren't necessarily the sharpest tools in the shed and I don't want to cause them to have to think.

      #!/usr/bin/perl -w ################################################## # use strict;
    Above is the most common way I start my scripts.

    Other variants include specific paths to a particular version of Perl. I bring that up because one financial house (that will not be named here) that I worked for used AFS to mount shared distributions of code including such things as Perl. We must have had at any given time 5 versions and/or patch levels of Perl being shared. One of the issues that caused was you really could not always predict which version /usr/bin/perl was.

    My defense against my scripts being run by a older version than I wanted was to give the full path to the version I wanted in the shebang line. For instance:

      #!/a/software/local/perl/perl-5.6.1/bin/perl -w ############################################### # use strict;

    Peter L. BergholdBrewer of Belgian Ales
    Unix Professional
(jeffa) Re: "perl args" or " args"
by jeffa (Bishop) on Jul 18, 2003 at 14:27 UTC
    Most of the time i use the she-bang line, but sometimes, when testing out code here at the Monastery, it is just as easy for me to "run" the text file as an argument to Perl than it is to chmod it. A third way i have found to run Perl scripts (i think i picked this up from eduardo) is to type perl, hit Enter, paste in the code, and then hit CNTL-D. But mostly i use the she-bang line. Mostly.

    While we are on the topic of running code posted here at the Monastery, check out Run and/or download code directly from perlmonk nodes. if you haven't already.


    (the triplet paradiddle with high-hat)
Re: "perl args" or " args"
by nimdokk (Vicar) on Jul 18, 2003 at 13:31 UTC
    We use the shebang line, except when testing. 90% of the Perl programs we use are set in the crontab, so that would get ugly if we had to add "perl /path/to/program" everytime :-). If I'm testing at the commandline, I might type "perl" or not, depending on my mood. But definitly if I want it to run in debug mode the first time or two.

    "Ex libris un peut de tout"

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://275371]
Approved by gjb
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-09-29 07:36 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.