Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello, Perl Monks..

I've been struggling to find a suitable solution (or direction) in regards to a parsing task I'm working on. The dataset looks similar to the following (without the dashes - those are simply used here to encapsulate each entry as an example:

-- 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 --
Now what I need to do is go through each entry and count the number of <ID>'s assigned to it, adding it to a hash I figure, like so: $myHash{totalForEntry}++, eventually ending up so I can print out a table like: IDS TOTAL 1 23 2 536 3 51 4 353 ..etc I'm not exactly sure how I can break down each section and count the total IDs assigned only within that entry. I had headed in the direction of 'paragraph mode' but what quickly threw me off of there was the empty line within each entry containing a 'deletion-time', which throws off the input separator. Here's some very messy code I had started with, lots of nonsense as I was experimenting here and there:

#!/usr/bin/perl use DateTime; use strict; use warnings; my $LOGFH = 'testdata'; my $/ = '\n'; my $x=0; open(LOGFH) or die("Couldn't open 'er!"); while(<LOGFH>) { #chomp; print $_, "\n"; $x++; last if $x == 2; } # #print $_, "\n"; # if ($_ =~ m!\|(.*)\|!){ # $id = $1 . "|"; # #print $id; } elsif ($_ =~ m!creationDate:\s+(\d+)!){ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localt +ime($1); $dt = DateTime->from_epoch( epoch => $1 ); print $dt->year; } #last; }

Monks, do you have any pointers for me in regards to which direction I should be taking this to solve the problem? I'm in no way looking for a handout - I like a challenge and have been thinking this over for the past day, but figured a little community input wouldn't hurt! :) Many thanks, VoidWander

In reply to Parsing multi-line record with varying data by VoidWander

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (2)
    As of 2018-01-21 09:44 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (227 votes). Check out past polls.