[Israel.pm] Fwd: [Telux] Next Meeting: "High-Level Programming Concepts Using Perl 6" on 22-March

Evgeny evgeny.zislis at gmail.com
Sat Mar 14 14:17:26 PDT 2009


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 <migo at homemail.com> 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'
>



More information about the Perl mailing list