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

    Your code as it stands does not compile. It is therefore likely that the code which you have posted is not the code which you are actually running, so you'll realise that there's not much point in trying to debug it.

    Can you post the actual code which you are running?

      your are right, I just figured that out. It seems now I am getting the results I had the code intended for.

        Don't obliterate node content just because you decided your question didn't need to be asked. On node obliteration.

        I wouldn't downvote a question for just being mistaken about the cause of a problem. But I'll always downvote a node that's been wiped clean of content.


        Dave