Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > eval package

Reply
Thread Tools

eval package

 
 
George Mpouras
Guest
Posts: n/a
 
      09-06-2013
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 ?
 
Reply With Quote
 
 
 
 
George Mpouras
Guest
Posts: n/a
 
      09-07-2013
Στις 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.
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      09-07-2013
On 07/09/2013 17:58, George Mpouras wrote:
> Στις 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?

--
Ruud

 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      09-07-2013
Στις 7/9/2013 19:31, ο/η Dr.Ruud *γραψε:
> On 07/09/2013 17:58, George Mpouras wrote:
>> Στις 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to eval or not to eval? Marc Girod Perl Misc 2 04-19-2011 01:13 PM
eval('07') works, eval('08') fails, why? Alex van der Spek Python 6 01-08-2009 08:24 PM
Different behavior between eval "07" and eval "08" Liang Wang Perl Misc 8 02-02-2008 08:31 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM



Advertisments