Front page | perl.beginners |
Postings from March 2002
RE: getting literal name of a variable
Thread Previous
|
Thread Next
From:
Wagner-David
Date:
March 30, 2002 09:39
Subject:
RE: getting literal name of a variable
Message ID:
113A7A0D1F47D511B92E00D0B7E03DAB0187BCCC@pmail02.vikingfreight.com
Instead of trying that you would probably be better off using a hash and var1, vars2 as the keys. In the context that you are doing the split and assignment, I don't believe you will get the $var1, $var2, etc but the values of the split.
Wags ;)
-----Original Message-----
From: zentara [mailto:zentara@highstream.net]
Sent: Saturday, March 30, 2002 09:15
To: beginners@perl.org
Subject: getting literal name of a variable
Hi,
This question is either so easy, I'm overlooking the answer,
or it is beyond me.
I want to automatically print a variable's name.
For example:
###################################
#!/usr/bin/perl
use warnings;
use strict;
my $string = '1,2,3,4';
my @a = (my $var1, my $var2, my $var3, my $var4)= split (/,/, $string);
foreach my $element (@a) {print "elementname"\t$element\n}
##################################
this prints:
elementname 1
elementname 2
elementname 3
elementname 4
I want:
'var1' 1
'var2' 2
'var3' 3
'var4' 4
Is there a way of getting the variable's name as a literal automatically,
without resorting to a hash?
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Thread Previous
|
Thread Next