3 ms·
Exactly. Perl's critics often completely overlook the degree to which liberal use of the map/reduce paradigm can simplify the graphical representation of your c
by peteretep 12y ago
Exactly. Perl's critics often completely overlook the degree to which liberal use of the map/reduce paradigm can simplify the graphical representation of your code and allow the powerful list processing features to be brought to bear. Consider:
use strict; use warnings; use List::Util
qw/reduce/;
map { print } join "\n", "Distribution of grades by letter:",
map { sprintf( "\t%s: %s student%s", @$_, $_ -> [1] == 1 ? '' : 's' ) }
map { my $c = $_ ; sort { $a -> [0] cmp $b -> [0] }
map { [ $_, $c->{$_} ] } keys %$c } reduce { $a->{chr(ord($b->[1]))}++; $a } {},
map { printf( "List of students with failing grades:\n\t%s\n", join ', ' ,
map { $_->[0] } grep {ord $_->[1] >68} @$_); @$_} reduce {push(@$a, $b); $a} [],
map { printf( "${^A}'s grade: %s\n" , $_ -> [1] ) if $_->[0] eq $^A; $_ }
map { $^A="Zsófia"; [split(/\s+/)] } <STDIN>
The use of strict and warnings making this particularly Modern Perl, you could almost be forgiven for thinking you were reading Haskell...
- Ultimatt 12y agoneeds use feature 'say'