Last active
January 2, 2016 16:49
-
-
Save sdeseille/8332401 to your computer and use it in GitHub Desktop.
Trouver la capacité d'accueil (en personne) regroupée par le nombre d'étoiles des établissements à partir des données en provenance de ce lien http://www.data.gouv.fr/fr/dataset/villages-de-vacances-classes-en-france
This file contains hidden or 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $infile = $ARGV[0]; | |
my @data_struct; | |
my %data_idx; | |
my %capacity_groupby; | |
my $index=0; | |
open my $ifh, '<:crlf', "$infile" or die "Impossible d'ouvrir en lecture le fichier $infile\n"; | |
my $line = <$ifh>; | |
chomp $line; | |
my @headers=split(/;/,$line); | |
foreach my $header (@headers){ | |
$data_idx{"$header"}=$index; | |
$index++; | |
} | |
while (defined($line = <$ifh>)) { | |
chomp $line; | |
my @records=split(/;/,$line); | |
push @data_struct,\@records; | |
} | |
close($ifh); | |
my $star=$data_idx{'CLASSEMENT'}; | |
my $capacity=$data_idx{'CAPACITÉ D\'ACCUEIL (PERSONNES)'}; | |
foreach my $record (@data_struct ){ | |
$capacity_groupby{$record->[$star]} += $record->[$capacity]; | |
} | |
foreach my $starclass (sort keys %capacity_groupby){ | |
print "$starclass: $capacity_groupby{$starclass}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment