I've searched high and low, and I still cannot get this to work. Any suggestions are welcome! TIA
#!/usr/local/bin/perl use strict; use warnings; no strict "subs"; no strict "refs"; my $line = 'fields: name addr zip state city'; my $var_city; print "$line\n"; $line =~ s/[-)(]//g; my @columnNames = split(/\s+/, substr($line,9)); print @columnNames; print "\n\n"; my $acount = 0; foreach my $name (@columnNames) { $acount++; print "name is: $name\n"; ${var_."$name"} = $acount; #print "nname is: ${"$name"}\n" } print "this should display 5: $var_city\n";
Here is the output:
fields: name addr zip state city nameaddrzipstatecity name is: name name is: addr name is: zip name is: state name is: city Use of uninitialized value $var_city in concatenation (.) or string at + G:\Projects\WebLogReporting\VarValAsVarName.pl line 28. this should display 5:
In reply to Using Variable Value as Variable Name by umama
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |