in reply to Re: Regex perplexity
in thread Regex perplexity
But I'm not sure how to make it grab the appropriate ending values. As is it grabs the last ones in the file.sub FindPositions { my $string = $_[0]; my $id = $_[1]; my ($firstQ, $firstS); my ($lastQ, $lastS); my $id_flag; my $line; # pipe-ize the string my $string_pipe = new FileHandle("echo \'$string\' |") or die; while (!(defined($id_flag) && defined($firstQ) && defined($firstS))) { $line = <$string_pipe>; $id_flag = 1 if ($line =~ /<a name = $id>/); $firstQ = $1 if ($line =~ /^Query:\s+?(\d+)[\sgcat]*(\d+)/) && do{ +$lastQ=$2}; $firstS = $1 if ($line =~ /^Sbjct:\s+?(\d+)[\sgcat]*(\d+)/) && do{ +$lastS=$2}; } foreach $line (<$string_pipe>) { $lastQ = $2 if ($line =~ /^Query:\s+?(\d+)[\sgcat]*(\d+)/); $lastS = $2 if ($line =~ /^Sbjct:\s+?(\d+)[\sgcat]*(\d+)/); } return ($firstQ, $firstS, $lastQ, $lastS); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Regex perplexity
by eweaverp (Scribe) on Jun 30, 2003 at 22:30 UTC | |
by eweaverp (Scribe) on Jun 30, 2003 at 22:50 UTC |