LPM: Subroutine references, or something ...
Steve Lane
sml at zfx.com
Thu Jul 15 15:07:05 CDT 1999
Rich Bowen wrote:
> I do thing weird thing where I figure out which subroutine I'm going to
> call based on arguments/parameters. Then I'll do something like:
>
> ($foo, $bar) = &{$routine}(@args);
>
> Works fine.
>
> The problem is that if I "use strict", I get "Can't use string
> ("whatever") as a subroutine ref while "strict refs" in use at fubar.pl
> line 99."
>
> My solution thus far has been to "use strict 'vars';" But I would like
> to understand what that error message really means, and how I can do
> what I'm doing another way, so that I can "use strict". Any help or
> pointers (references?) greatly appreciated.
the error message should tell you what's happening.
$routine must be a string that contains a subroutine name.
you're using it as a symbolic reference in your
statement, and this is prohibited under "use strict;",
which contains "use strict 'refs';".
i think (i'm not yet a master of symrefs) is to
either put a "no strict 'refs';" before the statement,
or to use an eval() instead.
--
Steve Lane <sml at zfx.com>
More information about the Lexington-pm
mailing list