in reply to Re: Re: Re: shebang line
in thread shebang line

Read carefully: "This leads me to believe that the shebang line in the imported file is ignored."

By imported, perlmongrel is referring to used or required files, NOT the main .pl file. Since in these cases Perl simply opens and reads the files, the shell and the kernel are out of the picture (at least from the execve perspective); this happens well after any shebang interpretation. So in that sense, he is right.

I believe, however, that Perl itself may, upon detecting a shebang line in an included file, honor at least the -w and -T switches, if present. The former in the usual sense, and the latter only insofar as it has to match the Taint-mode-ness of the main .pl file. However, I cannot remember where I read this and am not particularly certain of either of these points. Certainly, Perl WILL ignore the path to the perl interpreter if it differs from that of the running instance.

As to having an "invisible" CR (^M) *between* #!/path/to/perl and -w, balderdash! No Win/DOS editor would put anything but CR-LF into a text file, and those only go at the ends of lines. So if anything, adding a -w would move an extraneous CR (inserted by a Win/DOS editor) from right after #!/path/to/perl to just after the -w, in which location, as I explained in an earlier post, it is ignored by Perl.

Using ASCII mode to FTP the files, or using one of several CR-stripping mechanisms (of which your regex is one) would emeliorate the problem.

dmm

Replies are listed 'Best First'.
Re: Re(4): shebang line
by perlmongrel (Acolyte) on Jan 05, 2002 at 03:09 UTC
    dmm writes: "I believe, however, that Perl itself may, upon detecting a shebang line in an included file, honor at least the -w and -T switches, if present."

    After running some tests, I found that this is true when perl is run from the command line, such as this:

    % perl file.pl

    In this case, the interpreter does enable the -w and -T switches if they are present on the shebang line in the file passed to perl. However, this does not appear to be the case for imported files.

    Here's what I did:

    First, I created a file like this:

    #!/usr/bin/perl

    require "o.pl";

    exit 0;
    Next, I create the o.pl file:

    #!/usr/bin/perl -w

    print "y $s\n";

    1;

    When running the first file, no warning is printed. However, if you enable the -w switch on the shebang line of the first file, then the following warning will be returned:

    Use of uninitialized value in concatenation (.) or string at o.pl line 3.
    y

    Further, if you remove the -w switch from the shebang line in o.pl and from the main script, and instead use the warnings pragma in o.pl, the warning will be returned.

    Like this:
    #!/usr/bin/perl

    use warnings;

    print "y $s\n";

    1;

    I used perl 5.6.1 for testing.

    Thanks again!

    -perlmongrel

    Imagination is the one weapon in the war against reality. -- Jules de Gaultier