Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This was working ok until I started to get multiple occurences of the pattern ,the files I'm parsing are now appended to rather than overwritten :($foundit = 0; while (<$FH>) { $foundit = 1 if /^pattern/; } if ($foundit) { do some processing }
This is a possibility but it's very slow, which is why I wonder whether anybody has some other ideas about how to do this more efficiently ?open FH,"file" or die "Can't open file : $!\n"; $count1 = 0; while (<$FH>) { $count++ if /^pattern/; } close FH; open FH,"file" or die "Can't open file : $!\n"; $count2 = 0; while (<$FH>) { if (/^pattern/ and $count2 < $count1) { $count2++; } else { do some processing } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parse from last occurence of pattern match
by Cody Pendant (Prior) on Jun 07, 2006 at 10:41 UTC | |
|
Re: parse from last occurence of pattern match
by GrandFather (Saint) on Jun 07, 2006 at 11:58 UTC | |
|
Re: parse from last occurence of pattern match
by jhourcle (Prior) on Jun 07, 2006 at 11:59 UTC | |
|
Re: parse from last occurence of pattern match
by johngg (Canon) on Jun 07, 2006 at 13:27 UTC | |
|
Re: parse from last occurence of pattern match
by girarde (Hermit) on Jun 07, 2006 at 14:18 UTC |