Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I'm not sure I understand the structure of your file well enough to answer the question correctly. From what I understand, though, it seems to me that you have a file that looks something like this:
TI: ... AU: ... JN: ... TI: ... AU: ... JN: ...
and so on. Is the pattern repeating like that? And so for each section, you have, say, a TI, an AU, and a JN, and those 3 (or however many) headers and content constitute one "section"?

The solution that chromatic provided will work for a structure like this, but the resulting data structure may not look like you expect. You could dump it out to see quickly enough what it looks like, but I just thought I'd explain quickly.

You're going to end up with a hash called %sections, where the possible headers in the file (TI, AU, and JN) are the keys, and the values are arrays of all of the lines pertaining to those sections. So, for example, say that the 5th "section" in your file looked like this:

TI: Foo AU: Bar JN: Baz
Now you want to get the data for that section. You can access that information like this:
# the index is 4 because the array index starts # at 0, btw my $ti = $sections{'TI'}[4]; my $au = $sections{'AU'}[4]; my $jn = $sections{'JN'}[4];
Just in case it needed explaining.

In reply to Answer: How do I split a file into separate sections? by QandAEditors

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 drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2014-08-30 17:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (293 votes), past polls