Second Script Game: Finished Script

colomon on 2008-12-24T15:56:57

Quibbles in my last post aside, this one pretty much just worked beautifully:

my $file = "skaters.txt";

my @names;
my %scores;

my $skaters = open ($file);
for (=$skaters) -> $skater
{
    my @scores = split ",", $skater;
    my $name = shift @scores;
    push @names, $name;
    my $score = (([+] @scores) - (@scores.min() + @scores.max())) / 5.0;
    %scores{$name} = $score;
    say "$name => $score";
}
close $skaters;

my @sorted_names = sort { %scores{$^b} <=> %scores{$^a} }, @names;
say "Gold medal: {@sorted_names[0]}, {%scores{@sorted_names[0]}}";
say "Silver medal: {@sorted_names[1]}, {%scores{@sorted_names[1]}}";
say "Bronze medal: {@sorted_names[2]}, {%scores{@sorted_names[2]}}";

I was a little surprised the extra braces were required in the say statements, but it still is pretty darned elegant.