http://qs1969.pair.com?node_id=177129


in reply to when eval corrupts the invoker

$0 is Lvaluable so you could anticipate any changes to it. Simplistically you could just:

BEGIN{$0 = "foo"}

Or if you want to watch it's state just tie the thing:

package Progname; use Carp; sub TIESCALAR { my $class = shift; my $newname = shift; return bless \$newname, $class; } sub FETCH { my $self = shift; carp "The program name is being accessed.\n"; return $$self; } sub STORE { my $self = shift; my $attempted = shift; carp "An attempt is being made to change the program name to \"$at +tempted\".\n"; } 1;

And then:

use Progname; tie $0, 'Progname', "NewProgramName";