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
2010-01-07 06:05:06
Re: what he means - Perhaps a `BEGIN` block?
Chris Lutz
2010-01-07 06:06:40
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
2010-01-07 06:06:07
+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
2010-01-07 13:07:43