ygu95at has asked for the wisdom of the Perl Monks concerning the following question:
Help! A file of a list with 4 fields is used to match for another file. 1st field used as "name" for "name.xml" file to be seached. 2nd will eventually be used for the final text search. 3rd and 4th fields used to match location that precede the chunk that contains final text. The problem is 3rd and 4th sometimes will be with the text desire as one line, other times not. So, in that case I will need simply print the next line. the following code was not able to give a $`, anyone see why?
The normal part of name.xml look like this:
blah blah more lines of blah asdkb ------------------------ 0030 and 0022 are field 2 and 3
while (<>){ my @arr=split('#'); chomp(@arr); my $n=0; system("cat ff/$arr[0].xml >temp"); open FILE, "temp" or die $!; while(<FILE>){ if($n==1){$n=0;print "matched previously but now second line $_";} else { if (/$arr[2].*$\n/g) { if (($`=="") && $n==0)) { print "matched but text on next line";$n=1; } else { print "matched: $` \n";};};print "\r\n "; }; }; }; system("rm temp"); };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can NOT get content after matched place
by hippo (Archbishop) on Jun 05, 2013 at 17:12 UTC | |
by Anonymous Monk on Jun 05, 2013 at 17:14 UTC | |
by davido (Cardinal) on Jun 05, 2013 at 17:21 UTC |