Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

Hi,

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.


Comment on Re: Issue with #!usr/bin/perl
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;

    with:

    #!/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
      Thanks for the clarification. As I haven't used windows machine for perl scripting, never encounter such and I didn't know this before.

      Thanks.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-08-21 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (139 votes), past polls