Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 examining the Monastery: (6)
As of 2014-12-21 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (109 votes), past polls