bruno has asked for the wisdom of the Perl Monks concerning the following question:
Here's the issue. I need to load a method conditionally, the condition being that a certain module Foo::Bar is usable. So after asking in the chatterbox, the following snippet arose:
eval "use Foo::Bar"; unless ($@) { sub my_method { # Code } }
So far so good. It worked for a trivial test subroutine, but not for my real-life example. The thing is, Foo::Bar = PDL. And PDL adds a lot of new syntax. Now, the eval expression is being executed at runtime, but the my_method block has its syntax checked at compile time. So by the time that the syntax of the my_method is checked, PDL hasn't been loaded yet, and the module gives a syntax fatal error when the sub tries to
which is perfectly legal if PDL is loaded.$matrix(0,0) = $value;
I might be missing something here, but I surely don't know how to solve this. I would really appreciate some enlightenment!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Conditional loading of methods
by jasonk (Parson) on Dec 09, 2008 at 04:33 UTC | |
|
Re: Conditional loading of methods
by Tanktalus (Canon) on Dec 09, 2008 at 06:17 UTC | |
|
Re: Conditional loading of methods
by etj (Priest) on Jun 06, 2022 at 00:08 UTC |