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:[EMAIL PROTECTED]]
Sent: Saturday, March 30, 2002 09:15
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to