Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: log parser

by alex_fatu (Novice)
on Jun 17, 2013 at 10:50 UTC ( #1039331=note: print w/replies, xml ) Need Help??

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 (Prior) 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 (Priest) 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039331]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-05-28 21:44 GMT
Find Nodes?
    Voting Booth?