Since you're asking for opinions, instead of just giving a value judgment on your example as a whole I'll point out what I think about specific parts of your code. That way you can see not just the decision but the reasoning.

use strict; # strict is good ++ # Where's warnings? -- sub sum {my $x; $x += $_ for @_; $x } # poorly formatted -- sub avg {sum(@_)/@_} # poorly formatted -- # probably should use scalar @_ instead of just @_ here undef $/; # no need to slurp to do an average for a line -- open(my $F, 'skaters.txt'); # lexical filehandle ++ # please use three-argument open -- # no error check on a system call -- my @x = map{[split/,/]}grep{/\S/}split/\n+/,<$F>; # very poorly formatted -- # uses split to achieve what while ( <$F> ) would have done without th +e above slurp-- # makes me think well of those who call Perl line noise # combines two loops and two searches on one line += 0 # (good display of power, but could have built up # the data structure over time more clearly) for(@x){ @$_ = ($_->[0],avg(@{[sort{$a<=>$b}@{$_}[1..$#$_]]}[1..$#$_-2])) # nearly incomprehensible -- # partly due to unnecessary terseness and formatting -- # partly due to painful twists of syntax -- # (The hash solution on perlbuzz was simpler and clearer.) } @x = sort{$b->[1] <=> $a->[1]}@x; # poor formatting again -- printf "%-5s %-20s %-20s\n",$_+1,@{$x[$_]} for(0..2); # poor formatting again --

I'm sorry if the formatting comments bother you, but part of making a program easy to read and maintain is making it easy to distinguish the syntax tokens.

Another is to use as clear of syntax as you can in the first place. You're using lots of Perl features and smashing them together quite closely. You're doing math against punctuation variables in places where there are clearer ways. You're even assembling punctuation variables from one another ($#$_).

What you have is somewhat clever Perl code, but I wouldn't call it idiomatic, clear, or a preferred practice. Overall, I'd say it looks more like Perl than the Microsoft example cribbed from VB. I don't think it serves the purpose of evangelism through code, though, except maybe as a warning against Perl.

With warnings, some more whitespace, three-argument open, and some adjustments to the syntax in your for loop, it'd be a decent example of TIMTOWTDI. Right now, I'd call it a study in Perl syntax and maybe use it as a code maintenance question on a quiz. I think it's not quite ready to represent Perl as a clean, clear example of a powerful yet approachable tool for quickly developing applications.

If the point was to show simply the power of multiple ways to express the same process, you'd have a winner. Your example is certainly different. Since impressing people with the power and clarity of Perl with a program written in it is the cornerstone of the story with the original examples, I'm afraid I'd have to say your implementation might be counterproductive in that regard.


In reply to Re: winter games, perl, ice and bling by mr_mischief
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.