in reply to flexible string value matching in lists
Just wondering if there is a preferred logical approach to matching 'lists' to other 'lists'?
Yes. Put one of the lists in a hash.
In your case, if you make a hash of your fixed strings:
my %lookup = ( string1=>34, string2=>10, string3=>52, string4=>104, st +ring5=>7 );
Then your code becomes a simple process of splitting your complex strings and doing lookups:
my @bits = split ':', 'string2:string4:totalName'; my $name = pop @bits; my $total = 0; for my $bit ( @bits ) { $total += $lookup{ $bit }; } print OUTFILE "$name,$total";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: flexible string value matching in lists
by archeman2 (Novice) on Feb 16, 2017 at 17:44 UTC |