yes, there is, you can do
${'STR1'} = 'STR2';
to assign string STR2 to $STR1, however, you are absolutely right
that a hash can accomplish what you want, and is in fact
a much better way to do it than assigning random variables,
especially since it prevents you from overwriting your own
program variables :)
The way I would do it is this...
my %info;
for(@file) {
next if /^#/; skip line if it starts with a hash
chomp; # remove \n Update ACK! forgot this! Doh!
my($name,$val) = split '=', $_, 2; #split line into two
# values, on an = sign
next unless $val; # make sure you got something
$info{$name} = $val;
}
print "$info{OFFICE} - $info{NAME}\n";
very simple. you can also check for values by doing something like
if(exists $info{OFFICE}) {
print "Ofiice: $info{OFFICE}\n";
}
and you can get a list of all your info variables by doing
@keys = keys %info;
try it, and use this to see the results...
for(sort keys %info) {
print "$_: $info{$_}\n";
}
That will print a sorted list of all your keys with their values
Update forgot to chomp... fixed it... oops
- Ant