I have an array "@fields" that contains 6 elements.

I would like to sort the array by
$fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in
ascending order starting witht he first element before I print the
array.

I haven't been able to figure this out. Any help is greatly appreciated.

Below is the program.

#!/usr/bin/perl
use warnings;
use strict;
use POSIX;
use Data::Dumper;

my $fileOut = "testOut.txt";

open my $out, '>', $fileOut or die "ERROR opening $fileOut: $!";

my @fields;

while( <> ) {
  next unless /;/;
  chomp;
  my @data = split /;/;
  my($Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd) = @data[9,10,27,36,37,40];
    if( $Icell >= 1 && $Isect >= 1 && $Ichan >= 1 && $cfc >= 1 &&
$cfcq >= 1 && $rtd >= 1) {
      $rtd = sprintf "%.2f", $rtd/8/6.6/2;
      push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd);
    } else {
        next;
    }

    my @sorted_fields = sort { $a <=> $b } @fields;
    print join("\t",@fields),"\n";
    @fields = ();
    next;
}

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to