I converted that Perl 6 code to Perl 5 best I could and came up with
Here's a slightly more direct conversion
sub apply(&@) {
## ack, Class::Multimethods doesn't do variadic args :-/
return if @_ == 1;
my($func, $head, @tail) = @_;
local $_ = $head;
return $func->(), apply($func, @tail);
}
my @squares = apply { $_ * $_ } 2 .. 5;
print join(', ', @squares), $/;
__output__
4, 9, 16, 25
As the comment gives away, this isn't a direct conversion as it isn't using multimethods, so it uses an arg count hack to emulate the behaviour. Also to be an even closer conversion would require
apply to
tie @squares to a square generator (at least I think that's probably the closest thing you can get to binding to a lazy list in perl6 with raw perl5). So it's certainly no easy task to convert that wee
but powerful snippet directly to perl5!
HTH
_________
broquaint