On Tue, Dec 09, 2003 at 09:14:52AM +0100 [EMAIL PROTECTED] wrote:

> I would like to read something about passing code inside function. Lets say
> that:
> 
> This works:
> perl -e 'sub a(&){print(&{$_[0]}, "/n"};$_=0; a {$_++} foreach 1..100'
> 
> This don't work
> perl -e 'sub a{print(&{$_[0]}, "/n"};$_=0; a {$_++} foreach 1..100'

It will work once you do

    perl -e 'sub a{print(&{$_[0]}, "\n")}; a sub {$_++} foreach 1..100'

The prototype '&' will let perl treat a bare block as a codereference.
If there is no such prototype, you have to construct the code-ref
yourself, which can happen in several ways:

    \&func;     # reference to the named function 'func'
    sub { ... } # reference to an anonymous function

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to