OT: $0
Andy Armstrong
andy at hexten.net
Sun May 17 00:17:16 BST 2009
I've just noticed that:
$ cat bar.pl
#!/usr/bin/perl
print "I am called $0\n";
system "ps ax | grep bar";
$0 = $0;
print "I am called $0\n";
system "ps ax | grep bar";
{ ( my $exe, $0 ) = ( $0, '' ); $0 = $exe }
print "I am called $0\n";
system "ps ax | grep bar";
$ perl bar.pl
I am called bar.pl
95572 s003 S+ 0:00.01 perl bar.pl
I am called bar.pl
95572 s003 S+ 0:00.01 perl bar.pl
I am called bar.pl
95572 s003 S+ 0:00.01 bar.pl
In other words setting $0 gets rid of the 'perl ' from the process
name that ps sees - but only if you set $0 to something other than its
current value. Who knew.
So the question becomes what's the shortest one-liner that will cause
what ps displays to be the same as what $0 contains?
My first attempt is
( $0 .= ' ' ) =~ s/ $//;
--
Andy Armstrong, Hexten
More information about the london.pm
mailing list