Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: using regex with records

by Cristoforo (Curate)
on Jan 02, 2012 at 02:09 UTC ( #945824=note: print w/replies, xml ) Need Help??

in reply to using regex with records

Instead of reading in a record at a time, this solution reads the file line by line. 'ACCOUNT-dddddd' precedes the closed date and the created date follows the closed date. So, if this data is uniform as presented, you could enter the two dates into the %data hash for the current account number.
#!/usr/bin/perl use strict; use warnings; my (%data, $acct, $close_date, $create_date); while (<DATA>) { next if /^Remedy Account data:/ .. /^Remedy Case data:/; if (/^ACCOUNT-(\d+)/) { $acct = $1; } elsif (/^ClosedDate = ([-\d :]+)/) { $close_date = $1; } elsif (/^CreatedDate = ([-\d :]+)/) { $create_date = $1; $data{ $acct } = { closed => $close_date, created => $create_d +ate}; } } use Data::Dumper; print Dumper \%data;

This prints

$VAR1 = { '09782' => { 'created' => '2007-10-23 21:10:10', 'closed' => '2007-10-26 16:31:53' } };
Hope this helps :-)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-12-14 22:52 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (414 votes). Check out past polls.