Shawn H Corey <[email protected]> writes:
> Harry Putnam wrote:
>> Harry Putnam <[email protected]> writes:
>>
>>> However, using your suggestion:
>>> > $code->($var1, $var2);
>>
>> Something I forgot to ask about that.
>>
>> What if more than 1 of referenced sub routines needed vars passed in
>> but the needed vars were not the same?
>>
>> I'm guessing that using $code->() is not such a good idea. Whatever
>> data any subroutines may need, should have been supplied before the
>> `dispatch table' is called.
>
> my %dispatch = (
> 1 => sub { foo( $var1, $var2 ) },
> 2 => sub { bar( $var3, $var4 ) },
> );
>
Oh, yeah... I see now.
The more I get into this particular script... that will have a
dispatch table when finished, I'm beginning to see it would be handy
to call a second dispatch table in the middle of working thru the
first one.
Or do I need a different approach altogether?
The task at hand is:
work thru a large list of file names, taking one of a number of
choices on each name.
Some of the actions (at least one so far) will need to generate a list
from other available info to help with the choices.
For example: I match only the end element of filename to any matches
from another list. They may have different absolute names... but match
on the last part. So I end up with
(matching) name
some/path/name
some/other/name
some/yet/other/name
To help decide what to do next... I need to see sizes of each.
I've worked that code out using stat.
(matching) name size
some/path/name size
some/other/name size
some/yet/other/name size
So now I need to offer myself a way to choose one (a second dispatch
table?), that allows me to move back to the previous table for final
resolution with the newly filled variable in tow.
------- --------- ---=--- --------- --------
[...] various actions taken to create the necessary variable and
information ... leading up to this dispatch table
my %dispatch = (
1 => sub { foo( $var1, $var2 ) },
2 => \&cksz, # this action will create a list
# of files where user has to
# pick 1, then back to this
# table for final disposition
3 => \&mvtobla,
4 => \&dosomething,
5 => \&somethingelse,
6 => sub {print "call last to get out of here\n" and last;},
7 => sub (print "Goodbye\n" and exit;},
);
while(<1>){...}
my $filename;
sub cksz {
bla bla
size check reveals 4 names with fairly close matches on size
(now generate a dispatch table with the matched filenames
as choices with sizes shown. Where selecting one moves us
back into the prior dispatch table.)
}
A nudge here would really help.
For one thing, I see this notation for holding the dispatch table
up:
while(<1>){}
so it never falls until we exit the script.
Would something like this:
my $cnt = 0;
while( $cnt < 1 ){
..action..generate dispatch table;
choose $filename;
cnt++;
}
Drop me back into the prior dipatch table.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/