Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Better way to perform "double split" ?

by oha (Friar)
on Nov 11, 2009 at 09:41 UTC ( #806443=note: print w/replies, xml ) Need Help??


in reply to Better way to perform "double split" ?

use strict; use warnings; use Parse::RecDescent; use Data::Dumper; my $g = Parse::RecDescent->new(<<'EOG'); main: head row(s) /\Z/ { [$item[1], @{$item[2]}]; } | <error> head: /.*/ /-*/ { $item[1]; } row: date time num { [@item[1..3]]; } date: /\d\d\d\d-\d\d-\d\d/ time: /\d\d:\d\d:\d\d/ num: /[\d\.]+/ EOG my $data = join '', <DATA>; print Dumper($g->main($data)); __DATA__ Timestamp 10.72.218.82:cpu_busy ---------------------------------------------------------------------- +--------- 2009-11-05 17:59:52 1.501 2009-10-15 17:39:52 2.501 2009-12-25 17:19:52 3.501
will return the following, skipping empty lines and spaces, or generate a detailed error if data is invalid.
$VAR1 = [ 'Timestamp 10.72.218.82:cpu_busy', [ '2009-11-05', '17:59:52', '1.501' ], [ '2009-10-15', '17:39:52', '2.501' ], [ '2009-12-25', '17:19:52', '3.501' ] ];
Update: changing the row: rule returning a DateTime will also verify if the date is correct, improving the error detection while parsing.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-01-24 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?