strider corinth has asked for the wisdom of the Perl Monks concerning the following question:

Hi, all. I've been wrestling with this problem for a few hours now, and it seems to be a little beyond my reach. $0 seems not to work for me in Perl 5.8.0, whereas it works fine in an identically configured Perl 5.6.(0|1):
[ strider@isengard[pts/3] (16:07) ~/old-homedir ] % perl5.8.0 -e '$0 = "blork"; system( "ps -auxw" ); ' | grep blork strider 2561 0.0 0.4 2632 1036 pts/3 S 16:07 0:00 perl5.8 +.0 -e $0 = "blork"; system( "ps -auxw" ); strider 2563 0.0 0.1 1400 436 pts/3 S 16:07 0:00 grep bl +ork [ strider@isengard[pts/3] (16:07) ~/old-homedir ] % perl5.6.1 -e '$0 = "blork"; system( "ps -auxw" ); ' | grep blork strider 2564 0.0 0.3 2448 968 pts/3 S 16:07 0:00 blork strider 2566 0.0 0.1 1400 436 pts/3 S 16:07 0:00 grep bl +ork
So we know the platform supports setting the program name with $0; I've even tested with a C program, which worked fine (and was compiled with the same compiler used for 5.8.0). The only difference seems to be the Perl version. perlvar and perlfaq8 both agree that 5.8.0 still supports $0.

Does anyone have any ideas?

Replies are listed 'Best First'.
Re: $0 Problems
by belg4mit (Prior) on Sep 09, 2002 at 21:02 UTC
    This is a known problem and has been discussed on p5p, check the archives from http://lists.perl.org.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

      Thanks for the pointer. I checked there, and it looks like they've found the problem's source, but no solution has yet been discussed, save hacking the source, obviously. Is there some other way to accomplish this, or is that my only option until the problem is fixed? I'm currently working with Linux and Solaris; an answer that would work with either of those would be great. Could something written in XS emulate it portably?

      --

      Love justice; desire mercy.
        I doubt it, but for the sake of argument, how would XS be better than fixing the source?

        --
        perl -pew "s/\b;([mnst])/'$1/g"

Re: $0 Problems
by blakem (Monsignor) on Sep 09, 2002 at 21:06 UTC
    Looks like a perlbug to me... I get the same results as you on my RH7.3 box.

    p.s. just a little trick, you can avoid matching the grep process in the processes listing by using grep b[l]ork

    -Blake