Bruno Vecchi just left a tidied up version of the Perl code which I last posted. That code was a little ‘functional programming’ example, which I wrote to
- deal with the guilt of my not knowing that one could do this in Perl
- as an educational aside, creating a Perl version of what my new Groovy code was doing
And I did say that the reader ‘could tidy it up’, which he has taken up and done in style :-)
Well, when someone both contributes and teaches me something, it does not deserve to remain hidden away in the comments section. So, here it is for everyone else to learn a little from, along with me :-)
#!perl
use strict;
use warnings;
use feature 'say';
# init (quick day:date map)
my @days = (
[ 'MON', "2009/04/06" ],
[ 'TUE', "2009/04/07" ],
[ 'WED', "2009/04/08" ],
);
# data manip (closure)
sub dataManip {
my $p = shift;
return sub {
my $day = shift @$p;
return $day->[1];
}
}
# show
my $lister = dataManip(\@days);
while ( my $date = $lister->() ) { say $date }


