Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: $0 inconsistency?

by choroba (Cardinal)
on Apr 13, 2022 at 17:08 UTC ( [id://11142961]=note: print w/replies, xml ) Need Help??


in reply to $0 inconsistency?

If your tooling depends on the value of $0, note that $0 can be changed.
{ local $0 = 'my program'; print $0; # my program system 'ps'; # <- works even here, at least on my Linux box. } print $0; # Back to the old values. system 'ps'; # ditto
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: $0 inconsistency?
by Perlbotics (Archbishop) on Apr 13, 2022 at 17:46 UTC

      Eh... not quite. Setting argv[0] in the process should work on most POSIX systems. That change is an additional thing it does for Linux, and notes the limit for that.

      This is on a Mac.:

      $ perl -e '$0="my really awesome process name"; sleep 60;' & [1] 73413 $ ps PID TTY TIME CMD 70164 ttys002 0:00.05 /opt/local/bin/bash 677 ttys004 0:05.06 /opt/local/bin/bash 73413 ttys004 0:00.03 my really awesome process name
Re^2: $0 inconsistency?
by misterperl (Pilgrim) on Apr 15, 2022 at 12:59 UTC
    tyvm I just copied it in case somewhere else it expected it otherwise:
    $_=$0; s|.+/||;
    Cheers thx for the thoughtful reply!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found