Skip to content

Instantly share code, notes, and snippets.

@sdeseille
Last active January 2, 2016 16:49
Show Gist options
  • Save sdeseille/8332401 to your computer and use it in GitHub Desktop.
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
#!/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