> ...
>
> I'm not sure why you don't just pass $task as an argument to the
> report_xxx subs...?
>
> A closure (perldoc -q closure) would be the long way around unless
> I've missed something:
>
> my $task;
> my $iter;
> my $report_static = sub { my $ref = shift;
> print $ref->[$iter++];
> ....
> };
>
> my $report_dynamic = sub( my $ref = shift;
> print $ref->[$iter++];
> ...
>
> #MAIN_CODE START
> ....
> foreach $task (@tasks) {
> if ( .... )
> $report_static->(\@tasks);
> ...
> else
> $report_dynamic->(\@tasks);
> ...
> }
> }
>
>
You could also simplify the closure since @tasks is in the closure's
lexical scope, eg,
my $report_static = sub { print $tasks[$iter++]; ... };
foreach $task (@tasks) {
if (...)
$report_statics->();
else
$report_dynamic->();
...
}
But with everything in lexical scope, you could just pass any needed
arg's directly and
eliminate the closure altogether.
--
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/