Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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?


Comment on Re^2: log parser
Download Code
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 Anonymous Monk on Jun 17, 2013 at 10:59 UTC
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-24 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (243 votes), past polls