Created
August 16, 2011 14:45
-
-
Save masak/1149245 to your computer and use it in GitHub Desktop.
Perl 6 makes code look nicer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Perl 5 version: | |
use constant INFINITY => 2 ** 32; | |
sub choose_column { | |
my ($self) = @_; | |
my $r = $self->linked_matrix; | |
my $column_with_minimal_ones; | |
my $minimal_ones = INFINITY; | |
for (my $h = $r->R; $h ne $r; $h = $h->R) { | |
if ($minimal_ones > $h->S) { | |
$minimal_ones = $h->S; | |
$column_with_minimal_ones = $h; | |
} | |
} | |
return $column_with_minimal_ones; | |
} | |
Perl 6 version: | |
method choose-column() { | |
my $r = self.linked-matrix; | |
return min :by(*.S), ($r.R, *.R ...^ $r); | |
} | |
'Nuff said. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Porting Perl 5 code to Perl 6 (a task I've been doing lately with IRC::Utils) really makes you aware just how superior Perl 6 is to Perl 5. The only area I think Perl 5 takes the cake is documentation.