in reply to Command line to array

MeowChow probably didn't suggest this one because it's horrible practise, but I think you get away with something like this provided that you didn't give a damn about security:

my @list=('test', 'Hello!'); my $func_name=shift @list; &$func_name(@list); sub test { print @_; }

To my suprise, this works fine.

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Re: Command line to array
by merlyn (Sage) on Apr 26, 2001 at 05:59 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); }