Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Parsing multi-line record with varying data

by Kenosis (Priest)
on Aug 09, 2013 at 18:11 UTC ( #1048817=note: print w/ replies, xml ) Need Help??


in reply to Parsing multi-line record with varying data

Building upon BrowserUk's suggestion, perhaps the following will be helpful:

use strict; use warnings; use Data::Dumper; $/ = 'rn:'; my %hash; my $entry = 1; while (<DATA>) { chomp; /\S/ and $hash{ $entry++ } = () = /id-info:/g; } print Dumper \%hash; __DATA__ rn: uid:<user>, <irrelevant-text> id-info: <URL> | <ID> | <random-string> creation-time: 1366069064 rn: uid:<user>, <irrelevant-text> id-info: <URL> | <ID> | <random-string> id-info: <URL> | <ID> | <random-string> id-info: <URL> | <ID> | <random-string> creation-time: 1366069064 rn: uid:<user>, <irrelevant-text> id-info: <URL> | <ID> | <random-string> id-info: <URL> | <ID> | <random-string> deletion-time: 1367949064 creation-time: 1366069064 rn: uid:<user>, <irrelevant-text> creation-time: 1366069064

Output:

$VAR1 = { '4' => 0, '1' => 1, '3' => 2, '2' => 3 };


Comment on Re: Parsing multi-line record with varying data
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-12-27 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (177 votes), past polls