in reply to Re^2: getting the name of a variable to use as string
in thread getting the name of a variable to use as string

First, as tachyon says, I'm quite curious how you've gotten this information into all these variables, and why you didn't just put them into a hash to begin with. But assuming that's done by somebody else in code you don't control...

You're approaching the problem backwards. Instead of taking a variable and getting the name out, take the name and turn it into a variable, with a symbolic reference. Something like this should work, though I haven't tested it:

foreach my $i (qw(foo1 foo2 foo3 ... foon)) { $hash{$i} = $$i; }

Replies are listed 'Best First'.
Re^4: getting the name of a variable to use as string
by tilly (Archbishop) on Sep 17, 2004 at 14:50 UTC
    Not only does it not work, but I already explained why in this thread.

    Furthermore if recommending symbolic references I'd strongly suggest mentioning the problems with using them, and also mentioning how to turn off strict.pm for that block (which they should be using).

Re^4: getting the name of a variable to use as string
by pmneve (Novice) on Sep 20, 2004 at 18:57 UTC
    I'm trying to put data in the hash as noted in my reply to tachyon. Can't always use DBI (which solves the issue when I can).

    Thanks!