in reply to perl vs she-bang perl

Devel::PL_origargv will tell you the arguments passed to Perl itself.

On Linux, I've not been able to figure out any official technique to determine whether or not the file was started via the shebang. If you go via /proc/$$/cmdline or similar, you just see a "rewritten" command line, so that a script started by typing ./ looks like perl ./

However, I have found an interesting heuristic that seems to work on my machine. If you read the 10th field from /proc/$$/stat (it's a number representing the number of minor page faults occurred during the running of the script), I've noticed it's about 25% higher when the script is run via a shebang.

Update:... hmm... interestinger and interestinger... I habitually use the shebang #!/usr/bin/env perl, but if you hard-code the path to the Perl executable (like #!/usr/bin/perl) then the second field of /proc/$$/stat is pretty clear.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: perl vs she-bang perl
by vsespb (Chaplain) on Mar 06, 2013 at 23:36 UTC
    Yep, #!/usr/bin/perl can be easy detected. It's even displayed differently in process list. As for /usr/bin/env - I suspect you can probably check parrent process and find its name?