Skip to content

Instantly share code, notes, and snippets.

@antoinecourtin
Created March 23, 2015 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoinecourtin/3416a10a4e6a923e5c96 to your computer and use it in GitHub Desktop.
Save antoinecourtin/3416a10a4e6a923e5c96 to your computer and use it in GitHub Desktop.
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