in reply to Re: log parser
in thread log parser

oke, i found the problem.

the next code print a msg if word "eroare" is found:

#!/usr/bin/perl use strict; use warnings; print "searching using regexp...\n"; my $a = "start"; open(my $in, "<", "DirectX.log") or die "Can't open DirectX.log: $! +"; #print $a; while (<$in>) { # assigns each line in turn to $_ #print "Just read in this line: $_"; $a = $a . $_; } if ($a =~ /eroare+/) { print "found eroare\n"; } close $in or die "$in: $!";


can anyone tell me how can i make it to print every occurance of the match?

Replies are listed 'Best First'.
Re^3: log parser
by hdb (Monsignor) on Jun 17, 2013 at 10:59 UTC

    Now you read the whole file into $a (which can be done more efficiently) but what you want is something like

    while (<$in>) { # assigns each line in turn to $_ #print "Just read in this line: $_"; if( /eroare/ ) { # checks $_ print; } }
Re^3: log parser
by 2teez (Vicar) on Jun 17, 2013 at 11:04 UTC

    check the while loop usage:

    while(my $line=<$in>){ if ($line=~/eroare/i){ print "Found"; } }

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re^3: log parser
by Anonymous Monk on Jun 17, 2013 at 10:59 UTC