Guruguhan N wrote: > > Hi John, Hello,
> Thanks for the quick help. I have resolved the problem > with your suggestions. But now I am facing a new problem. Actually > the goal is to get the statistics for each of the data column stored > in a file (FilterMC_3bar_data.out). This file has the following data > as its content: > > RUN a1 a2 a3 weight > sig1 sig2 sig3 4 0.359575 0.253987 > 0.359575 1.271019 43898.7 19675.6 -24223.1 5 0.359921 > 0.253987 0.359921 1.271995 43861.3 19666.1 > -24195.2 6 0.359575 0.254332 0.359575 1.271364 > 43892.0 19662.2 -24229.8 7 0.587633 0.213477 0.587633 > 1.875554 28791.2 15898.3 -12892.8 8 0.587978 > 0.213477 0.587978 1.876530 28775.9 15892.2 -12883.7 9 > 0.587633 0.213822 0.587633 1.875899 28786.8 15889.6 > -12897.2 > > This is the code intended do it. > > #!/usr/bin/perl -w > > $output_file = "FilterMC_3bar_data.out"; > > if (-s $output_file) { You shouldn't use file test operators to determine whether or nor to open files as there is no guarantee that the test will be valid by the time you open the file. > open ( INTER,$output_file) || die "Cannot open: \nReason: $!\n"; > my @temp = <INTER>; If the file were empty you could have determined that by seeing if @temp had any data. @data or warn "$output_file is empty\n"; > chomp @temp; > my $response = shift(@temp); # Remove the header line > > foreach $i ( 0 .. $#temp ) { > $filter_data = $temp[$i]; > $filter_data =~ s/^\s+(.*)/$1/; #Remove the leading white spaces > @data2 = split /\s+/, $filter_data; You can write the previous three lines in one line: @data2 = split ' ', $temp[ $i ]; > foreach $j ( 0.. $#data2) { > $data3[$i][$j] = $data2[$j]; > } > } > } > #Till this part of the code is already existing, written by earlier > colleague. > > @data3[0..$#temp] = [EMAIL PROTECTED], 0..$#temp; > @data3 = map[sort {$a <=> $b } @$_],@data3; > > foreach $i ( 0 .. $#data2) { > foreach $j ( 0 .. $#data3) { > print " $data3[$j][$i]\n"; > } > } > > The above code with your suggestions gives an output like > > -24223.1 > -24195.2 > > [snip] > > 28775.9 > 28786.8 > > I want to sort each and every column separately so as get statistics > for each. can you please tell me what necessary changes would enable > me to do the same. It looks like you need to transpose the rows and columns #!/usr/bin/perl -w use strict; $output_file = 'FilterMC_3bar_data.out'; open INTER, $output_file or die "Cannot open: $output_file\nReason: $!\n"; my @data; while ( <INTER> ) { next if /[a-z]/i; # Remove the header line my @temp = split; my $index = 0; push @{ $data[ $index++ ] }, $_ for @temp; # use the next line instead if you don't want the first "RUN" column # push @{ $data[ $index++ ] }, $_ for @temp[ 1 .. $#temp ]; } @data or die "$output_file was empty.\n"; @data = map [ sort { $a <=> $b } @$_ ], @data; for ( @data ) { print "@$_\n"; } __END__ 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>