[Melbourne-pm] $0 behaviour

Mathew Robertson mathew.blair.robertson at gmail.com
Sun Jul 15 22:20:04 PDT 2012

Hi list,

I having been having some quirky behaviour when assigning $0...
For me this turned out to be as a result from this:

$0 = abs_path(dirname($0))."/".basename($0);

ie: make the process name (as shown in top/ps, be the name of the script -
instead of the perl binary.
Which worked well when running "pidof whatever.pl", "ps auxww | grep
whatever.pl", but not so much for "killall whatever.pl".

Some Googling has turned up the problem/cause:

perl version is: v5.14.2

So I run the example shown -> which shows that the patch is applied.  Upon
further investigation, I think the implementation could be refined, ie: in
my code above, only the first 16 characters of string are chomped, thus
leaving the program title with part of the the basepath of the script. In
my case I worked around it using Sys::Prtcl->prctl_name($BASENAME),

The suggested change to this enhancement would be, if $0 points at a
script, then change $0 assignment so that Perl grok's the rightmost part of
the path. ie: leave $0 as-is, but modify this patch as so.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20120716/fc3cd065/attachment.html>

More information about the Melbourne-pm mailing list