CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [Laurent_R] Trying to break from “while loop” : Edit Log



testerV
Novice

Nov 23, 2012, 4:44 PM


Views: 3082
Re: [Laurent_R] Trying to break from “while loop”

Hi Lauren, Fish!
Thanks guys for your help!
I made 3 log files to test my script.

File 1 with Match1, Match2 and Match3:

Match1_Er_11111111111111111
Match2_TOOL_111111111111111
Match3__3333333333333333333

File 2 with Match1, Match2 and Match3:

Match1_Er_11111111111111111
Match2_TOOL_111111111111111
Match3__3333333333333333333

File 3 with Match1 and Match2:

Match1_NO
Match2_NO_Tool

When I added the “next function”, it still prints only:

Match3__3333333333333333333
Match3__3333333333333333333
End exits.
I did not try Laurent script yet, it is very complicated.

Here is my code with the Next function:
#!/use/bin/perl -w
use strict;
use warnings ;

my $line ;
my $dir = 'C:/Error_logs' ;
my @logfile = grep( -M $_ < 1, <$dir/*.dat>);
# print @logfile,"\n" ;
foreach my $logfile ( @logfile ) {
open my $logfile_fh,'<', $logfile or die "Can't open $logfile $!\n" ;

LINE: while ( $line = <$logfile_fh> ) {
chomp $line ;
next LINE if $line !~ /Match3/g ;

if ($line =~ /Match1/) {
print $line, "\n" ;

}

if ($line =~ /Match2/) {
print $line,"\n" ;

}

last if$line =~ /Match3/g ;
print $line,"\n" ;
}
close $logfile_fh ;
}


Code


Code

Code

In Reply To


(This post was edited by testerV on Nov 23, 2012, 7:32 PM)


Edit Log:
Post edited by testerV (Novice) on Nov 23, 2012, 7:32 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives