in reply to How do I write subs that take bare blocks as args?
Thank you both. I've found the relevant sections now in perlsub and in the Camel book. For the record, it was as easy as:
sub each_item (&@) { my $test = shift ; foreach ( @_ ) { return 0 unless ( eval &$test ) } return 1 ; }
Thanks again.
Update: On reading kvale's node a little closer, I tried changing my code to:
sub each_item (&@) { my $test = shift ; foreach ( @_ ) { return 0 unless &{$test} } return 1 ; }
...which also worked. Is there any advantage/disadvantage to this over eval?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How do I write subs that take bare blocks as args?
by educated_foo (Vicar) on Jun 28, 2002 at 06:33 UTC | |
Re: Re: How do I write subs that take bare blocks as args?
by Courage (Parson) on Jun 28, 2002 at 06:37 UTC |