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

Re: lying about program name

by hippo (Bishop)
on Jun 14, 2018 at 10:47 UTC ( [id://1216619]=note: print w/replies, xml ) Need Help??


in reply to lying about program name

Typos aside, it is your understanding of the name change which does not tally. It is the name for the O/S which is being changed. Demo:

#!/usr/bin/perl use strict; use warnings; print "I am $0 (@{[join ' ', @ARGV]})\n"; system ("ps $$"); shift; exit unless @ARGV; my @args = ('bar', 'foo.pl', @ARGV); system { '/usr/bin/perl' } @args;

Running this I see:

$ ./foo.pl 1 1 I am ./foo.pl (1 1) PID TTY STAT TIME COMMAND 3717 pts/0 SN+ 0:00 /usr/bin/perl ./foo.pl 1 1 I am foo.pl (1) PID TTY STAT TIME COMMAND 3719 pts/0 SN+ 0:00 bar foo.pl 1

So the name in the O/S has changed to 'bar' but within the script, $0 is still foo.pl since that is the file which perl is executing. Additionally, if you call system ('./foo.pl') the O/S uses the hashbang line to re-exec perl with the script as argument (as in the initial invocation in my run above), so your aliasing there would have no effect even at the O/S level.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found