You've reimplemented List::Util::sum.

You open without checking whether it succeeded.

open my $input_fh, '<', 'skaters.txt' or die "Can't read skaters.txt: $!";

I see no reason to undef $/ and then split on /\n+/

my @skater_records = map { chomp; [ split /,/ ] } grep { /\S/ } <$input_fh>;

I'm not going to unravel the the rest. The whole thing reads like an obfuscation or attempt at golfing. This is a simple problem, and the solution is not difficult, but you've made it hard to read. You may have found that entertaining (and I might have as well), but it.doesn't have much more to recommend it.

Update with a solution.

use strict; use warnings; use List::Util qw( sum ); my $skaters_file = shift @ARGV || 'skaters.txt'; my @top_three; open my $skaters_fh, '<', $skaters_file or die "Can't read skaters file '$skaters_file': $!"; while ( my $csv_line = <$skaters_fh> ) { chomp $csv_line; my ( $name, @scores ) = split /,/, $csv_line; # remove highest and lowest score @scores = sort { $a <=> $b } @scores; shift @scores; pop @scores; my $mean_score = sum( @scores ) / scalar @scores; push @top_three, { name => $name, score => $mean_score }; @top_three = reverse sort { $a->{score} <=> $b->{score} } @top_thr +ee; @top_three = @top_three[ 0 .. 2 ] if 3 < scalar @top_three; } close $skaters_fh or die "close failed: $!"; foreach my $skater ( @top_three ) { print "$skater->{name}: $skater->{score}\n"; } __END__ Guido Chuffart: 88.2 Jack Creasey: 85.8 Cecilia Cornejo: 85.4

It's not super efficient, but it doesn't read every record into memory (it just retains the top three), so it can handle any number of records without exhausting RAM. Nothing too tricky, I don't think.


In reply to Re: winter games, perl, ice and bling by kyle
in thread winter games, perl, ice and bling by mobiusinversion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.