in reply to Select only desired features from a text
The general procedure is to first read the file that contains the interesting mapping, read the mapping into a hash, and then traverse the second file and do the transformation of these lines based on the hash.
Something like this:
use 5.010; use strict; use warnings; use autodie; my %map; open my $IN, '<', 'f1'; while (<$IN>) { my ($first, undef, $type, $fourth) = split; $map{$fourth} = $first if $type eq 'coord'; } close $IN; open $IN, '<', 'f2'; while (<$IN>) { my ($first, $rest) = split /\s/, $_, 2; if ($map{$first}) { print "not_$map{$first} $rest" } } close $IN;
Note that the variable names are quite terrible, because I don't know what the values stand for.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Select only desired features from a text
by remluvr (Sexton) on Mar 19, 2012 at 15:15 UTC | |
by moritz (Cardinal) on Mar 19, 2012 at 18:03 UTC | |
by bitingduck (Chaplain) on Mar 19, 2012 at 15:29 UTC |
In Section
Seekers of Perl Wisdom