Imagine this routine:
sub test(&&)
{
my $cr1 = shift;
my $cr2 = shift;
$cr1->();
$cr2->();
}
I know that I can call it like: test(\&sub1,\&sub2)but how can I call it the following:
test { print 1 },{ print 2 };
If I say that the subroutine accepts only one &, then sending the block will work. I don't know how to make it work with 2.
If I try to run it like this, I get:
Not enough arguments for main::test at script.pl line 38, near "},"
EDIT: Is there no way to call without sub?
source
share