Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: using regex with records

by Cristoforo (Deacon)
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 :-)


Comment on Re: using regex with records
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (17)
As of 2015-07-31 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls