On 6/22/05, Aditi Gupta <[EMAIL PROTECTED]> wrote:
> Since i'm using activestate perl on windows xp i don't know whether paste
> will work or not.
> I'll try the hash of array.

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to