On 12-05-17 03:36 PM, Chris Stinemetz wrote:
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.
Do you want the fields sorted or do you want records sorted? If you want
the records sorted, try:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;
# configuration
my $fileOut = "testOut.txt";
my $field_separator = quotemeta( ';' );
my $ICELL_INDEX = 9;
my $ISECT_INDEX = 10;
my $ICHAN_INDEX = 27;
my $CFC_INDEX = 36;
my $CFCQ_INDEX = 37;
my $RTD_INDEX = 40;
# main
open my $out_fh, '>', $fileOut or die "ERROR opening $fileOut: $!";
my @fields;
while( <> ) {
next unless /$field_separator/;
chomp;
# split by separator
my @data = split /$field_separator/;
# load variables
my ( $Icell, $Isect, $Ichan, $cfc,
$cfcq, $rtd )
= @data[ $ICELL_INDEX, $ISECT_INDEX, $ICHAN_INDEX, $CFC_INDEX,
$CFCQ_INDEX, $RTD_INDEX, ];
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 ];
}
}
my @sorted_fields = sort {
$a->[0] <=> $b->[0]
|| $a->[1] <=> $b->[1]
|| $a->[2] <=> $b->[2]
|| $a->[3] <=> $b->[3]
|| $a->[4] <=> $b->[4]
|| $a->[5] <=> $b->[5]
} @fields;
print {$out_fh} Dumper \@fields;
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
_Perl links_
offical site : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help : http://perlmonks.org/
documentation : http://perldoc.perl.org/
news : http://perlsphere.net/
repository : http://www.cpan.org/
blog : http://blogs.perl.org/
regional groups : http://www.pm.org/
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/