This looks a little familiar. *grin*

First, use local $/ = "\n\n";, not a regex.

What's going on with the printing is that the part of the script that reads in the datafile and builds up @records is reading in one complete record at a time, and putting its six elements into an anonymous array that gets pushed onto @records. The result is that @records contains array-refs to anon-arrays of records. So you're only printing the top level, which is just the array-refs, when the fact is that you've got a two-dimensional array (a list of lists, an array of arrays). You need to be printing one level deeper.

This can be confirmed by adding the following to your script:

use Data::Dumper; # All of your existing code goes here. print Dumper \@sorted_recs;

That will dump the data-structure held in @sorted_recs onto your display.

The easiest way to deal with this is just to iterate over the top level, and then dive into the lower level to do your printing, like this:

foreach my $record_ref ( @sorted_recs ) { foreach my $rec_line ( @{$record_ref} ) { print SUM2 $rec_line; } print SUM2 "\n"; # put that extra newline back, to # delimit the records. }

That dereferences the top level, one element at a time, and then subsequently, prints each line of each individual record.

I think you might find perlreftut (reference tutorial), perllol (lists of lists), and perlref (references) really informative. Oh, I almost forgot, perldsc (data structure cookbook).


Dave


In reply to Re: Lost contents of arrays... by davido
in thread Lost contents of arrays... by fiddler42

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.