ftumsh has asked for the wisdom of the Perl Monks concerning the following question:
I have some DOS (ie each line ends in \r\n) files that are look like (this is run on linux)open FH, "< $file"; while (<FH>) { # for each regex for my $re ( keys %{ $compiled->{'rx'} } ) { $compiled->{'rx'}{$re}++ if /$re/; } } close FH;
orfoo bar "99","END"
"99","END"
ie all files contain "99","END" but some contain other lines before it.
My problem is that I need to positively match the files containing _only_ the "99","END"
ie in the example files above, I have a regex that would match "foo", this would find the first file, however, what regex would find the second file? One of END wouldn't work because that would find the foo file.
The only idea I have is to embed perl in a regex and somehow test that if we have END and are on the first iteration of the while, it matches.
Any other ideas appreciated...
John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using a regex to determine if a string is the start of the FILE
by GrandFather (Saint) on Sep 18, 2008 at 11:56 UTC | |
by ftumsh (Scribe) on Sep 18, 2008 at 12:27 UTC | |
by GrandFather (Saint) on Sep 18, 2008 at 19:51 UTC | |
by ftumsh (Scribe) on Sep 29, 2008 at 11:33 UTC | |
by ftumsh (Scribe) on Sep 18, 2008 at 12:18 UTC | |
by moritz (Cardinal) on Sep 18, 2008 at 12:35 UTC | |
|
Re: using a regex to determine if a string is the start of the FILE
by salva (Canon) on Sep 18, 2008 at 12:46 UTC | |
|
Re: using a regex to determine if a string is the start of the FILE
by AnomalousMonk (Archbishop) on Sep 18, 2008 at 14:36 UTC |