Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

Title:
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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (11)
    As of 2015-07-28 07:32 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 (253 votes), past polls