[Israel.pm] Ho do I get the name of a variable?
Ido Perelmutter
ido50 at yahoo.com
Thu Jul 27 13:24:35 EEST 2006
That's really unnecessary. Simply use a backslash:
my @some_name = (1,2,3);
print "The contents of \@some_name are: @some_name\n";
Ido.
--- perl-request at perl.org.il wrote:
> From: "Offer Kaye" <offer.kaye at gmail.com>
> Subject: [Israel.pm] Ho do I get the name of a
> variable?
> Date: Thu, 27 Jul 2006 09:56:42 +0300
> To: "Perl in Israel" <perl at perl.org.il>
>
> 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
>
> > _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Perl
mailing list