Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Parsing multi-line record with varying data

by moritz (Cardinal)
on Aug 09, 2013 at 17:59 UTC ( #1048814=note: print w/ replies, xml ) Need Help??


in reply to Parsing multi-line record with varying data

Here is an example that reads through the example file, and prints each uid along with the number of id-info lines attached to it:

use strict; use warnings; use 5.010; local $/ = "--\n"; while (<DATA>) { if (/^rn: uid:(\S+),/m) { my $uid = $1; my $count = 0; $count++ for /^id-info:/mg; say "$uid: $count"; } } __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> # random empty line in each entry with 'deletion-time' deletion-time: 1367949064 creation-time: 1366069064 --

I hope it can serve as a starting point for you.

If you need more help, please provide example (not whited-out) input data along with exactly what output you are expecting.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-10-25 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (146 votes), past polls