On Sun, Jul 1, 2012 at 9:12 AM, Chris Stinemetz
<chrisstinem...@gmail.com> wrote:
> I have a two line pattern I would like to match and include 3 groupings.
>
>   59 REPT: EVDO: RNC 24 CP FAILURE SUMMARY SESSION RELEASE
>      RAN AUTH FAILURE PPP, ERROR CODE 51001
>
> For final outcome I would like:
>
> $1 = 24
> $2 = CP FAILURE SUMMARY SESSION RELEASE RAN AUTH FAILURE PPP
> $3 = ERROR CODE 51001
>
>
> while ( my $line = <$FIN> ) {
>   if ( $line =~ /EVDO:\s*RNC\s*(\d+)(.*\n{1}.*),(ERROR CODE\s*\d+)/m) {
>     print $line,"\n";
>   } else {
>     print "No Match\n";
>   }
> }
>
> I haven't had much luck matching the second line.
>
> Any help is greatly appreciated.
>
> Thanks,
>
> Chris

Hi Chris,
>From the code snippet. it appears you are trying to read the file a
line at a time. Therefore, you will not have the second line of input
available.
This means you have two options:
1) After matching the first line of input, read the next line of input
and see if it matches what is expected on the
second line ( you will have to save matching variables, $1 etc, from
first match ).
2) Read in the whole file at once (see perlvar $\ or the File::Slurp
module) then use the s and possibly m regular expression modifiers
(see perldoc perlre).
Also, you appear to be using .* in your regular expressions which is
greedy (it will keep matching as long as it can and will match the
subsequent text you wished to match). Therefore, you should either use
a character class or the question mark to indicate the match is
non-greedy. For instance:

([^,]+),ERROR
(.*)?,ERROR

HTH, Ken

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to