Created
March 23, 2015 10:43
-
-
Save antoinecourtin/3416a10a4e6a923e5c96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
my $fic="villeMondeacmuseees.txt"; | |
open(OUT,">resulat.txt"); | |
open(FIC,"$fic") or die ("Erreur lors de l'ouverture du fichier $fic"); | |
my @liste; | |
my @fichier; | |
while( my $line = <FIC> ) { | |
push(@fichier,$line); | |
my @elem = split (/\t/,$line); | |
my $var="$elem[0]_$elem[1]"; | |
push(@liste,$var); | |
} | |
close(FIC); | |
@liste=&Uniq(@liste); | |
my %tab=(); | |
foreach my $l (@liste) | |
{ | |
$tab{$l} = "" ; | |
} | |
foreach my $ligne (@fichier) | |
{ | |
my @elem2 = split (/\t/,$ligne); | |
my $v="$elem2[0]_$elem2[1]"; | |
my $temp=$tab{$v}; | |
$temp="$temp\t$elem2[2]"; | |
$tab{$v} = $temp; | |
} | |
foreach my $k (keys(%tab)) | |
{ | |
my $glam=$tab{$k}; | |
my @g = split (/\t/,$glam); | |
my @pays_ville = split (/_/,$k); | |
my $cpt=-1; | |
foreach my $i (@g) | |
{ | |
$cpt++; | |
} | |
print OUT "$cpt\t$pays_ville[0]\t$pays_ville[1]\t"; | |
foreach my $i (@g) | |
{ | |
print OUT "$i, "; | |
} | |
print OUT "\n"; | |
} | |
sub Uniq { | |
my (@IsInclude) = @_; | |
my %hashTemp = map { $_ => 1 } @IsInclude; | |
my @IsInclude_out = sort keys %hashTemp; | |
return @IsInclude_out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment