Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Issue with #!usr/bin/perl

by nagalenoj (Friar)
on Mar 13, 2013 at 05:23 UTC ( #1023109=note: print w/replies, xml ) Need Help??

in reply to Issue with #!usr/bin/perl


Yes, you're right. It is not useful in windows machine. This line instructs the operating system the place which the interpreter is available.

Shabang is optional. Not mandatory to be given.

In windows machine, this line is skipped as like any other comment line.

Replies are listed 'Best First'.
Re^2: Issue with #!usr/bin/perl
by tobyink (Abbot) on Mar 13, 2013 at 07:56 UTC

    Actually on Windows, the shebang line is not ignored. The Operating System ignores it, but Perl pays attention. Compare:

    #!/usr/bin/perl print undef;


    #!/usr/bin/perl -w print undef;

    The former issues no warning; the latter warns about using an uninitialized value.

    This is because in Perl, the shebang line performs two roles. It's used by Unix-like operating systems as a "dispatch mechanism" - to decide which program should interpret the script. And on all operating systems Perl parses it looking for command-line options. It doesn't honour all command line options found there (e.g. -M) but does some (like -w and -t).

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      There's also this useful trick for writing perl scripts that will run using whatever is the first perl in the $PATH:
      #!/bin/sh exec perl -x $0 #!perl # your perl code goes here

      "But why not use #!/usr/bin/env perl?", I hear you cry.

      Because env isn't always in /usr/bin - it's in /bin on some obscure platforms - and there can be "issues" with passing arguments to the executable via env.

      Thanks for the clarification. As I haven't used windows machine for perl scripting, never encounter such and I didn't know this before.


      what's the difference between shebang -w vs. use strict; use warnings; ? Thinking of putting a shebang at the top of all my scripts that say #!/perl/shebang - be a win32 japh you know this is pointless, even with the -w.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023109]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-04-21 18:01 GMT
Find Nodes?
    Voting Booth?