eval package

G

George Mpouras

I have a module /SomeDir/SomeCode.pm with a package name retrieved from
its dynamic name, but when I use eval


( my $PackageName = __FILE__ ) =~s/(?i)^.*?([^\/]+?)\.pm$/$1/;
eval "package $PackageName;";

....


the calling script can not find its subroutines.
( the $PackageName has the correct value "SomeCode" )
If i remove eval and just say


package SomeCode;
....

everything is ok; What happens here ?
 
G

George Mpouras

Στις 7/9/2013 01:18, ο/η George Mpouras έγÏαψε:
I have a module /SomeDir/SomeCode.pm with a package name retrieved from
its dynamic name, but when I use eval


( my $PackageName = __FILE__ ) =~s/(?i)^.*?([^\/]+?)\.pm$/$1/;
eval "package $PackageName;";

...


the calling script can not find its subroutines.
( the $PackageName has the correct value "SomeCode" )
If i remove eval and just say


package SomeCode;
...

everything is ok; What happens here ?



i do not think there is a solution to that. eval is pushing the
evaluated code one scope deeper than the current, so actually it is not
the same package any more.
 
D

Dr.Ruud

Στις 7/9/2013 01:18, ο/η George Mpouras έγÏαψε:
I have a module /SomeDir/SomeCode.pm with a package name retrieved from
its dynamic name, but when I use eval

( my $PackageName = __FILE__ ) =~s/(?i)^.*?([^\/]+?)\.pm$/$1/;
eval "package $PackageName;";

the calling script can not find its subroutines.
( the $PackageName has the correct value "SomeCode" )
If i remove eval and just say

package SomeCode;

everything is ok; What happens here ?



i do not think there is a solution to that. eval is pushing the
evaluated code one scope deeper than the current, so actually it is not
the same package any more.

Just put the code in the same string. But what on earth are you trying
to achieve? Maybe you are looking for AutoLoader?
 
G

George Mpouras

Στις 7/9/2013 19:31, ο/η Dr.Ruud έγÏαψε:
Στις 7/9/2013 01:18, ο/η George Mpouras έγÏαψε:
I have a module /SomeDir/SomeCode.pm with a package name retrieved from
its dynamic name, but when I use eval

( my $PackageName = __FILE__ ) =~s/(?i)^.*?([^\/]+?)\.pm$/$1/;
eval "package $PackageName;";

the calling script can not find its subroutines.
( the $PackageName has the correct value "SomeCode" )
If i remove eval and just say

package SomeCode;

everything is ok; What happens here ?



i do not think there is a solution to that. eval is pushing the
evaluated code one scope deeper than the current, so actually it is not
the same package any more.

Just put the code in the same string. But what on earth are you trying
to achieve? Maybe you are looking for AutoLoader?




its a complex file parsing and flow chart service , delivering results
to multiple destinations.
At some point may execute user defined functions from pluggable external
(Perl) modules.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top