given what you've said I'd try something like this:
#!/usr/bin/perl use strict; open IN, 'file'; open OUT, ">outfile"; my %HASH = (); my @RUNNING = (); my $INSIDE = ""; # keep track of where we are while(local $_ = <IN>) { chomp; if(/^\s*$/) { # we have an empty line $HASH{$INSIDE} = @RUNNING if $INSIDE; @RUNNING = (); # empty running now that its c +opied $INSIDE = ""; # no longer inside anything next; # keep going } elsif(/^\s*(pos\s*\=\s*\d+)$/i) { # this should be the "header" $INSIDE = $1; next; } elsif($INSIDE) { push @RUNNING, $_; } } close IN; for(sort keys %HASH) { print OUT "$_\n", map { $_ .= "\n"; } @{$HASH{$_}}; } close OUT;
*shrugs* it passed strict and warnings.. but is untested.. also, if you're opening a BIG textfile.. IE megs large.. you might run into problems.. it'd get a tad more complex to fix that duplicate records problem with a large file but look at seek(), tell() and keeping records of where you are at the begining of each "id" in the OUT file.. have fun..

-brad..

In reply to Re: Arrays and regular expressions by reyjrar
in thread Arrays and regular expressions by mel1rose

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!
  • 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, details, 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, summary, 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.