Lonewolf wrote: > > I have a 12 field 3000 line file (| delimited) and need to check the 7th > entry of each line to see what it is, and based on that it needs to be > written out to a file with a new entry in the 7th spot. I could do it with > a few entries to check, but the permutation is of 253 different choices. > > Example: > data.txt > ww-a10991t|rolls|5765|365.3|385|12|RR|Rolls Royce|2|0|1|A > ww-a10991w|rolls|5763|365.3|385|12|RR|Rolls Royce|2|0|1|A > ww-a10991b|rolls|5790|365.3|385|12|RR|Rolls Royce|2|0|1|A > > RR is keyed as category 235 so the outputed file will be: > ww-a10991t|rolls|5765|365.3|385|12|235|Rolls Royce|2|0|1|A > ww-a10991w|rolls|5763|365.3|385|12|235|Rolls Royce|2|0|1|A > ww-a10991b|rolls|5790|365.3|385|12|235|Rolls Royce|2|0|1|A > > My problem is just that the size of the switching and checking seems > attrocious to do. > > Thoughts, suggestions?
You should probably use a hash to map the choices to their new values: my $file = 'data.txt'; my %choices = ( AA => 1, BB => 2, ... RR => 235, ... ZZ => 253, ); open FILE, $file or die "Cannot open $file: $!"; while ( <FILE> ) { my @fields = split /\|/; $fields[ 6 ] = $choices{ $fields[ 6 ] } if exists $choices{ $fields[ 6 ] }; do_something_with_modified_data( @fields ); } close FILE; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]