-- Bill -Sx- Jones <[EMAIL PROTECTED]>

> I have the habit of doing:
>
>          last if (substr($vFlag, 1, 3) eq 'END');
> $vSub = \&Sneex   if (substr($vFlag, 1, 5) eq 'SNEEX');
> $vSub = \&Admin   if (substr($vFlag, 1, 5) eq 'ADMIN');
> $vSub = \&Reports if (substr($vFlag, 1, 7) eq 'REPORTS');
> $vSub = \&Logs    if (substr($vFlag, 1, 4) eq 'LOGS');
> $vSub = \&Targets if (substr($vFlag, 1, 7) eq 'TARGETS');
> $vSub = \&Usenet  if (substr($vFlag, 1, 6) eq 'USENET');
>
> (substr($_, 0, 1) eq '[') ? next : &$vSub;
>
>
> (NOTE:  Obviously NOT all of the 668 lines of program code
> is here, so this doesn't stand on it's own two feet...)
>
>
> Q: Is there a better way?

Use a hash as a jump table, with the keys
being what you extract and the values being
subs. If the string is regex-able then
something like:

    my %jumpz =
    (
        SNEEX => \&sneez,
        ...
    );

    ...

    my ($name) = $vflag =~ /\w+/;
    my $sub = $jumpz{$name}
        or croak "$$: bogus vflag: $vflag"

double-check the syntax, but if you feel
like shortening the result:

    $jumpz{($vflag =~ /\w+/)[0]}

or
    $jumpz{($vflag =~ /\w+/)[0]}->($vflag)

should return the sub or execute it on the fly.

That or a goto $jumpz{(...)[0]} should dispatch the thing
completely.

--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582

Reply via email to