Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created September 1, 2013 14:09
Show Gist options
  • Save tomcha/6404676 to your computer and use it in GitHub Desktop.
Save tomcha/6404676 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
binmode STDOUT,":utf8";
use Data::Dumper;
my $papix = {
name => 'papix',
affiliation => 'namba.pm',
perl => 60,
python => 50,
ruby => 50,
php => 80,
binary => 30,
};
my $boolfool = {
name => 'boolfool',
affiliation => 'namba.pm',
perl => 40,
python => 10,
ruby => 20,
php => 30,
binary => 10,
};
my $moznion = {
name => 'moznion',
affiliation => 'hachioji.pm',
perl => 100,
python => 70,
ruby => 80,
php => 50,
binary => 50,
};
my $binarian = {
name => 'binarian',
affiliation => 'hachioji.pm',
perl => 10,
python => 11,
ruby => 1,
php => 100,
binary => 100,
};
my $uzulla = {
name => 'uzulla',
affiliation => 'hachioji.pm',
perl => 1,
python => 0.01,
ruby => 0.5,
php => 4,
binary => 0.01,
};
my $people =[ $papix, $boolfool, $moznion, $binarian, $uzulla];
my @language = ( 'perl', 'python', 'ruby', 'php', 'binary');
for my $name (@$people){
$name->{sum} = 0;
for my $lang (@language){
$name->{sum} = $name->{sum} + $name->{$lang};
}
}
my $avarage = {perl => 0, ruby => 0, python => 0};
for my $name (@$people){
$avarage->{perl} += $name->{perl};
$avarage->{ruby} += $name->{ruby};
$avarage->{python} += $name->{python};
}
for my $key (keys(%$avarage)){
$avarage->{$key} /=5;
}
print Dumper $avarage;
for my $name (@$people){
my $output_txt = $name->{name}.":\n";
for my $lang (@language){
$output_txt .= $lang.":"."★"x($name->{$lang}/20)."\n";
}
print $output_txt."\n";
}
my $highscore = {};
for my $name (@$people){
if($name->{perl} >= 60){
unless($highscore->{$name->{affiliation}}){
$highscore->{$name->{affiliation}} = [$name->{name}];
}else{
push(@$highscore->{$name->{affiliation}}, $name->{name})
}
}
}
print Dumper $highscore;
my $dump_txt;
$dump_txt = "[\n";
for my $name (@$people){
$dump_txt .= "\t{\n";
for my $key (keys(%$name)){
$dump_txt .= "\t\t\"$key\":".$name->{$key}."\n";
}
$dump_txt .= "\t}\n";
}
$dump_txt .= "]\n";
print $dump_txt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment