in reply to Re: Parsing a tab delimited file
in thread Parsing a tab delimited file
with@molecules = <MOL>; map { chomp; $_ = quotemeta; } @molecules;
anyway, if i wanted to be fancy.push my @molecules, quotemeta chomp while <MOL>;
with$bigRegex = join '|', @molecules;
to test for word boundaries. also, i have a feelingmy $bigRegex; ($bigRegex .= join( '|', '\b'. $_ . '\b' ) ) for @molecules;
will speed up the regex by testing by longest words first, but i may be wrong.my $bigRegex; $bigRegex = join '|', map { "\b$_\b" } sort { length $b <=> length $a +} @molecules;
by the way, i like your use of ?() in the regex. i recommend readers investigate this powerful construct by reading about it in perlre.#!/usr/bin/perl -w use strict; open( MOL, "molecules" ) or die "ack! - $!"; push my @molecules, quotemeta chomp while <MOL>; close MOL or warn "ack - $!"; my $bigRegex; $bigRegex = join '|', map { "\b$_\b" } sort { length $b <=> length $a } @molecules; open( LOCUS, "locus" ) or die "ack! - $!"; my @locus = <LOCUS>; close LOCUS or die "ack! - $!"; for(@locus) { print if( scalar( split /\t/ ) >= 6 && /^([^\t]*\t)?($bigRegex)/ ); }
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Parsing a tab delimited file
by graff (Chancellor) on May 13, 2002 at 20:59 UTC | |
by particle (Vicar) on May 13, 2002 at 22:37 UTC |