in reply to Simple RegEX text parser

Since your data set is fairly small, you might want to consider building the regex out of the pieces you're looking for:

#!/usr/bin/perl -w use strict; our ($Gene, $Target, $Input) = qw/gene.txt target.txt input.txt/; open Gene or die "$Gene: $!\n"; open Target or die "$Target: $!\n"; open Input or die "$Input: $!\n"; my $gene = join "|", grep {chomp} <Gene>; my $target = join "|", grep {chomp} <Target>; chomp(my $input = <Input>); close $_ for qw/Gene Target Input/; my $verbs = 'localizes to|held|located in|localization|translocated to +|targets|reaches|exported|export'; # Note corrected 'split' regex for my $sentence (split /\. [A-Z]/, $input){ my $found; for ($sentence =~ /($gene).*?($verbs).*?($target)/ig){ print "$_\t"; $found++; } print "\n" if $found; }

Output:

PfAMA1 located in micronemes PfROM1 located in Golgi AMA1 held micronemes AMA1 held micronemes

--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: Simple RegEX text parser
by planetscape (Chancellor) on Dec 30, 2008 at 16:02 UTC
      Regexp::Assemble is to join regexps. Regexp::List is to join strings into a regexp. They're in the same distribution.
Re^2: Simple RegEX text parser
by I-Box (Acolyte) on Dec 30, 2008 at 16:42 UTC

    Thanks Oko1..your code was really handy....I always wanted my code to be short and smart...