savio has asked for the wisdom of the Perl Monks concerning the following question:
I want to sort the rows in descending order according to their first field, so I typed the following script:.0000000001;2;1;.5;.2 .5;2;1;.5;.5 0.3;1.5;.5;.5;.2 1;1;.7;1;1 .4;1;.4;1;.5
but it doesn't work!#!/usr/bin/perl use strict; use diagnostics; use warnings; my $fh; my @lines = (); my @sortedlines = (); open($fh, "<", "filename") or die "I cannot open the file: $!\n"; chomp(@lines = <$fh>); @sortedlines = sort { $b =~ /(^\d*\.*\d+);/ <=> $a =~ /(^\d*\.*\d+);/ +} @lines; print "SORTED LINES = @sortedlines\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting file rows and copy them in an array
by choroba (Cardinal) on Dec 11, 2014 at 15:22 UTC | |
by savio (Initiate) on Dec 11, 2014 at 15:48 UTC | |
by choroba (Cardinal) on Dec 11, 2014 at 16:00 UTC | |
by Anonymous Monk on Dec 11, 2014 at 15:59 UTC | |
|
Re: Sorting file rows and copy them in an array
by toolic (Bishop) on Dec 11, 2014 at 15:26 UTC | |
by savio (Initiate) on Dec 11, 2014 at 18:01 UTC |