
testerV
Novice
Nov 23, 2012, 4:44 PM
Post #9 of 14
(7168 views)
|
Re: [Laurent_R] Trying to break from “while loop”
[In reply to]
|
Can't Post
|
|
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 ; }
(This post was edited by testerV on Nov 23, 2012, 7:32 PM)
|