tags:

views:

114

answers:

3

I want to test one of my Perl scripts. I want to modify the "$0" value during compile time. Is that possible?

+2  A: 

Try it and find out.

$ perl -e 'print "$0\n"; $0="abcd"; print "$0\n"'
-e
abcd

But I'm not sure what you mean about modifying $0 "during compile time".

Nate C-K
Re: what he means - Perhaps a `BEGIN` block?
Chris Lutz
+4  A: 

Yes. Yes it is.

alt text

friedo
I want to +1, but this should be a comment, and it seems irresponsible to reward this kind of behavior with reputation points.
Chris Lutz
@Chris, I added a more explanatory illustration.
friedo
By hotlinking an image?
Doug Neiner
+7  A: 

Whenever you have a question about a special variable, read its entry in perlvar. Here's the first part of the entry for $0, which up front implies that you can assign to it:

   $PROGRAM_NAME
   $0      Contains the name of the program being executed.

           On some (read: not all) operating systems assigning to $0
           modifies the argument area that the "ps" program sees.

The entry goes on and on about the various implications of assigning to it.

Do you have an example of what you are trying to do and how it's not doing what you want it to do?

brian d foy