in reply to Self-writing code revisited

I know you can do something like this with hashes, but I don't want to use hashes.
Requisite warnings: Why it's stupid to use a variable as a variable name. Seriously, read all three pages.

But since you asked, you are looking for Symbolic references. Your code would be written as

#!/usr/bin/perl -w use strict "vars" ; my $data ; my @splitter ; $data = "testval,1" ; @splitter = split( "," , $data ) ; ${$splitter[ 0 ]} = $splitter[ 1 ] ; print ${$splitter[ 0 ]}, "\n";

where I added a print for fun. This creates a maintenance headache, and note that your $testval variable is never associated with a declaration (my or our), so if the last line were print $testval, "\n"; you'd get a compile time error from strict 'vars'.

Also note that what I've written creates a package variable, not a lexical variable. This means you might have weird scoping issues pop up depending on what you are actually doing.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.