[Israel.pm] Ho do I get the name of a variable?

Offer Kaye offer.kaye at gmail.com
Thu Jul 27 09:56:42 EEST 2006


Hi,
To get a variable's name, I've come up with the following method -
stringify it using single-quotes, remove the leading sigil, return the
name.
I was wondering if there is a better way?

Example code:

my @some_name = (1,2,3);
print "The contents of " . var_name('@some_name') . " are: @some_name\n";

sub var_name {
	my $var_string = shift;
	$var_string =~ s/^.//;
	return $var_string;
}

Thanks,
-- 
Offer Kaye



More information about the Perl mailing list