Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 musing on the Monastery: (6)
As of 2015-08-01 01:56 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 (285 votes), past polls