Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

colomon (8994)

colomon
  (email not shown publicly)

Journal of colomon (8994)

Wednesday December 24, 2008
10:56 AM

Second Script Game: Finished Script

[ #38157 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.