5 ms·
Blocks are also available in Perl, in the form of anonymous subroutines. They follow Perlish conventions for argument handling (rather than having a neat inlin
by flatwhatson 15y ago
Blocks are also available in Perl, in the form of anonymous subroutines. They follow Perlish conventions for argument handling (rather than having a neat inline syntax like Smalltalk or Ruby), but they're most definitely the same thing!
my $block = sub { say "w00t, blocks!" };
my $closure = sub { $block->(); say "w00t, closures!" };
You'll have to look further for something Ruby does that Perl doesn't :)
- gte910h 15y agoYeah, smalltalk blocks are almost identical to ruby blocks. Article just acted like that was a ruby invention (which they corrected) My comment had nothing to do with perl.
- flatwhatson 15y agoI probably should have replied to rtomayko's comment rather than your own. I'd edit the tree, but it's immutable!
- draegtun 15y agoAnd in Perl6 you can drop the sub bit: my $block = { say "w00t, blocks!" }; And there are also pointy blocks for neater stuff: my $pointy_block = -> $text { say "$text, blocks" }; $pointy_block("ne@t");