in reply to regex issue
In the case of Perl, the best alternative to symbolic references, in many cases, is to use a hash. After all, the global symbol table itself is just a special kind of hash. If it's good enough for the goose, it's good enough for the gander.
use strict; # Always, for now. use warnings; # Always, while developing code. my %symbols; open INFILE, "<mydata.txt" or die "Can't open infile.\n$!"; while ( my $key = <INFILE> ) { my $value; unless ( $value = <INFILE> ) { die "Uneven key/value pairs!"; } $value =~ s/^\s+|\s+$//g; $symbols{$key} = $value; } print "$_: $symbols{$_}\n" for keys %symbols;
Also, please don't keep asking the same question with different titles. If you don't get good answers to your initial question, it's probably because it was unclear. In that case, you can follow-up in the same thread with refined details as to what you're looking for.
Dave
|
|---|