So the block (sub) works without the word "sub" only if it is the first parameter?
On Sat, Mar 14, 2009 at 10:40 PM, Mikhael Goikhman <[email protected]> wrote: > On 14 Mar 2009 19:20:05 +0200, Evgeny wrote: >> >> Actually, in ruby I can have a method that accepts multiple blocks. >> Blocks don't HAVE to come as the last argument. >> def (&first_block, &second_block) >> will work as well. > > The same syntax works in Perl. We just spoke about DSL (syntactic sugar). > > Moreover, in Perl you can pass any number of anonymous functions > (closures) defined inline, something that is for example impossible in > Python by design. > > run(sub { do something; do well }, sub { do something else }); > >> But in perl, I tried to do the same - by replacing sm(&$) to be sm($&) >> - but it does not work. So does that mean that in perl I can't have >> the block where ever I want, and pass it as the last argument? Why? > > Nope, this is incorrect. I demonstrated this in the previous message: > > Given /regular-expression-here/, sub { some code here }; > > This works too (no need for parentheses if you specify prototypes): > > run $first_arg, sub { "second" }, 3, sub { "forth" }; > > Regards, > Mikhael. > > -- > perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e' > _______________________________________________ Perl mailing list [email protected] http://perl.org.il/mailman/listinfo/perl
