[Israel.pm] Ho do I get the name of a variable?
guy keren
choo at actcom.co.il
Thu Jul 27 13:36:52 EEST 2006
why would you want to remove the trailing character? it adds ambiguitiy,
since @some_name, $some_name and %some_name are 3 different variables.
when i print variable names, i just print them. why add confusion?
--guy
On Thu, 2006-07-27 at 09:56 +0300, Offer Kaye wrote:
> 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,
More information about the Perl
mailing list