in reply to Lost contents of arrays...

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