> Using a hash of arrays will not necessarily preserve the order... If you don't want to worry about sorting the order of the blocks i.e. doing it yourself then use Tie::IXhash (something like that on CPAN) to preserve the order, you then don't have to worry about unbalanced blocks and reassembly by applying an if defined type block. Easy.
Dan > > Using a hash of arrays will not necessarily preserve the order. Below > is the start of an array of arrays solution. I'll leave handling > unbalanced blocks and reassembling the pieces as an exercise for the > reader. > > my @blocks = (); > my $maxlen = 0; > while (<DATA>) { > chomp; > if (/^#/) { > push @blocks, []; > } elsif ($_) { > push @{$blocks[$#blocks]}, $_; > my $len = $#{$blocks[$#blocks]}; > $maxlen = $len if $len > $maxlen; > } > } > > __DATA__ > #block1 > aaa > ddd > > #block2 > bbb > eee > > #block3 > ccc > fff > -- Daniel Klose Mathematical Biology NIMR The Ridgeway Mill Hill London NW7 1AA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>