hello everybody, first of all i'd like to thank all of you for your time and help.. but i'm still stuck!!
The code which Dave sent: my @blocks = (); my $maxlen = 0; while (<DATA>) { chomp; if (/^#/) { push @blocks, []; } elsif ($_) { push @{$blocks[$#blocks]}, $_; my $len = $#{$blocks[$#blocks]}; $maxlen = $len if $len > $maxlen; } } I couldn't understand the line my $len = $#{$blocks[$#blocks]}; i referred to the programming perl book, i didn't understood why $# was used twice.. and in the John's mail.. $ echo " aaa aaa bbb bbb ccc ccc " | perl -l -00ne'my $i; $x[ $i++ ] .= $_ for split /\n/ }{ print for @x' I didn't understood the " | perl -l -00 " part.. please explain what is means.. Since i'm not good in using comples data structures, i obtained the different blocks in differernt text files using the following code: --------------------------------------------------------------------------- #!perl/bin/perl -w use strict; my $n = 7; my $count=0; my @aoa; my $file = "out.txt"; open (FH, $file) or die "couldn't open $file:$!"; while (<FH>) { push @aoa, [split/\n/]; } print "\n No.of rows: $#aoa"; my $last_val= ($#aoa/$n); my $lv = sprintf ("%.0f", $last_val); print "last val: $lv"; for(my $f=1;$f<$lv;$f++) { $file = "$f.txt"; open (OF, ">$file") or die "couldn't open $file:$!"; for my $i ($count..($n+$count)) { my $j=0; #{ print OF "$aoa[$i][$j]\n"; $count++; #} } } ---------------------------------------------------------------------- But I want to do it using the complex data structures. Hence, please explain the points which I couldn't understand. Thanks again, with regards, Aditi On 6/23/05, John W. Krahn <[EMAIL PROTECTED]> wrote: > > Aditi Gupta wrote: > > Hi Perlers, > > Hello, > > > I have a file as follows: > > > > #block1 > > aaa > > aaa > > > > #block2 > > bbb > > bbb > > > > #block3 > > ccc > > ccc > > > > and i want to append(or i should say merge) these blocks and get a file > like > > this: > > > > aaabbbccc > > aaabbbccc > > > > how can this be done using perl? > > please help.. > > > $ echo " > aaa > aaa > > bbb > bbb > > ccc > ccc > " | perl -l -00ne'my $i; $x[ $i++ ] .= $_ for split /\n/ }{ print for @x' > aaabbbccc > aaabbbccc > > > > John > -- > use Perl; > program > fulfillment > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > >