in reply to Re: Command line to array
in thread Command line to array

Fails on use strict though, because you're using a symbolic reference.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
How strict?
by frankus (Priest) on Apr 26, 2001 at 13:48 UTC
    Merlyn, how bad is it to do:
    use strict; no strict 'refs';
    From your post it sounds as though you disapprove, is this so? I'm concerned as I use jump tables quite often. AFAIK this isn't possible without undoing strict refs. Is there another way of doing jump tables? Or a healthier alternative?

    --
    
    Brother Frankus.

    ¤

      Have a list of approved subroutines:
      my %table = ( fred => \&fred, barney => \&barney, betty => \&betty, wilma => \&wilma, ); ... my $func = "betty"; $table{$func}->(@args); # call betty(@args);
      This ensures that $func can't go wild and execute metafunctions that aren't part of the plan. And this does work under use strict.

      -- Randal L. Schwartz, Perl hacker

      I have had to use this mode of subroutine array referring before. I used no strict only around the calling statement. This worked, but I assume it does still raise a number of issues about the correctness of breaking 'strict' code.
      { no strict; &$func_name(@list); }
        Normally using anonymous functions would be better for this. If the person wants to name their own function, they can construct the reference themselves.

        The glaring exception is in places like AUTOLOAD routines where you are constructing the function on the fly, giving it a real name, and then calling that...