Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

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

Thanks everyone for your tips. Taking bits from each, I created my own parser for the file.

#!/usr/bin/perl -wT #-*-cperl-*- use strict; my ( $laststate, $state, $nextstate ); open(SOURCE, "< $ARGV[0]") or die "Couldn't open $ARGV[0] for reading: $!\n"; # There are three possible line beginnings (ignoring whitespace): '(', + ':', and ')' # There are three possible line endings (ignoring whitespace): '(', ') +', and neither one while (<SOURCE>) { SWITCH: { # the first line in the file always starts with '(' # no other line will match this /^\(/ && do { $state = $laststate = 0; $nextstate = 1; # elevate the state last SWITCH; }; # lines beginning with ':' always have whitespace before it # these lines either maintain or elevate the state, never lower th +e state /^\s+:/ && do { $laststate = $state; $state = $nextstate; # here is where we analyse the line endings STATE: { # if the line ends with '(', elevate the state /\($/ && do { $nextstate++; last STATE; }; # if the line ends with ')', maintain the state? /\)$/ && do { last STATE; }; # other line endings elevate the state $nextstate++; } last SWITCH; }; # if the line contains only whitespace and ')', lower the state /^\s+\)$/ && do { $laststate = $state; $state--; $nextstate--; last SWITCH; }; } # analyse our state if ( $state != $laststate ) { # we changed state print "State Change!\t\t"; } print "$laststate\t$state\t$nextstate\n"; } close SOURCE;

I love the idea of DFA::Simple. The documentation for it sux, however. So I rolled my own based upon a review of my source file (which is still in idnopheq's scratchpad. Its just a shell so far. I'll move onto playing with real data now.

THX everone!
--
idnopheq
Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.


In reply to Re: Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.) by idnopheq
in thread Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.) by idnopheq

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
  • Outside of code tags, you may need to use entities for some characters:
            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 making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2014-09-02 10:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (21 votes), past polls