Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex Help pulling Data from a string

by chargrill (Parson)
on Dec 21, 2006 at 20:56 UTC ( #591192=note: print w/replies, xml ) Need Help??


in reply to Regex Help pulling Data from a string

There are probably CPAN modules lying around that can parse logfiles for you, but my first inclination would be to key off spaces (using split):

#!/usr/bin/perl use strict; use warnings; my @records; for my $logfile_line( <DATA> ){ next unless $logfile_line =~ m/logfiles.*\.log.*successfully/; my( $logfile, $day, $date, $time, $datfile, $size, $units ) = ( split( /\s/, $logfile_line ) )[ 0, 2, 3, 4, 9, 14, 15 ]; $logfile =~ s/.*\\(\w+)\.log/$1/; $datfile =~ s/.*\\(w+)\.dat/$1/; $units =~ s/\)$//; push @records, [ $logfile, "$day $date $time", $datfile, "$size $uni +ts" ]; } __DATA__ e:\logfiles\beardstownbase.log [3] Thu 22Jun06 08:07:19 - (006415) Sen +t file d:\data\58bn5904.dat successfully (25.0 Kb/sec - 859216 bytes)

Or something similar. Note that you're left with an AoA. And that this is completely untested. Update: Tested slightly, corrected list indices and scrubbed data. Update2: Missed the part about skipping lines that don't match. Adjust the "next unless" to suit, since I don't know what non-matching lines will/could possibly look like.



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2019-09-19 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (242 votes). Check out past polls.

    Notices?