I think that you are looking at a closure. As such, data are available as lexicals in the context in which your anonymous sub is defined. Usually you will want $fruit to go out of scope deliberately.
Also, add_entry does nothing with its argument, hence you would not be able to observe a difference:
Warning: untested code
#!/usr/bin/perl -w use strict; $|++; my $dispatch; { my $fruit = [ qw|apple orange pear| ]; $dispatch = { add => sub { return add_entry( $fruit ) }, }; } print scalar localtime, "\n"; sleep 1; print &{ $dispatch->{add} }, " <-- from sub \n";; sleep 1; print scalar localtime, "\n"; sub add_entry{ print scalar localtime, "$_[0] <-- in sub \n"; sleep 1; return scalar localtime; } __END__
In reply to Re: passing arguments in a dispatch table
by rinceWind
in thread passing arguments in a dispatch table
by CharlesClarkson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |