On Fri, Feb 27, 2015 at 8:24 PM, Martin G. McCormick
<[email protected]> wrote:
> Brock Wilcox writes:
>> I'm afraid a bit more context is needed to identify the problem. Could you
>> post your entire bit of code into a gist or pastebin or something for us
>> to
>> see?
>
> I'll do better than that. This is a script which is
> stripped of everything but the problem code. It is 20 lines long
> and here it is.
>
> #!/usr/bin/perl -w
> use strict;
>
> #Declare main variables.
>
> #main locals
> my @tasks;
> my $task;
> my $report_static;
> $report_static = sub {
> print "$task\n";
> };
>
> #MAIN_CODE START
> $tasks[0] = "red";
> $tasks[1] = "blue";
> $tasks[2] = "green";
> foreach $task (@tasks) {
> &$report_static;
> }
>
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);
...
}
}
--
Charles DeRykus
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/