|
|
|
|
J'ai une autre question concernant les tris en perl svp:
J'ai ce fichier texte:
#x y
1 5
44 2
3 74
2 11
Et en fait, j'aimerais le transformer en un nouveau fichier texte ou les x sont triés par ordre croissant:
donc le nouveau fichier texte serait:
#x y
1 5
2 11
3 74
44 2
Vous savez comment on peut faire ca svp?
merci.
Salut,
#! /usr/bin/perl
use warnings;
use strict;
my %h = ();
my $entete = <DATA>;
while (<DATA>){
next unless /^\d/;
my($cle,$val) = split /\s+/,$_;
$h{$cle} = $val;
}
print "$entete";
foreach (sort {$a <=> $b} keys %h){
print "$_ $h{$_}\n";
}
__END__
X Y
1 6
3 22
5 1
0 8
10 258
2 5401
Résultat[lamitest@localhost corbeille]$ perl a X Y 0 8 1 6 2 5401 3 22 5 1 10 258 [lamitest@localhost corbeille]$lami20j
|
Salut,
|