eval package

Discussion in 'Perl Misc' started by George Mpouras, Sep 6, 2013.

  1. 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 ?
     
    George Mpouras, Sep 6, 2013
    #1
    1. Advertising

  2. Στις 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.
     
    George Mpouras, Sep 7, 2013
    #2
    1. Advertising

  3. George Mpouras

    Dr.Ruud Guest

    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
     
    Dr.Ruud, Sep 7, 2013
    #3
  4. Στις 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.
     
    George Mpouras, Sep 7, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Newton
    Replies:
    3
    Views:
    9,429
    Brock Allen
    Apr 4, 2005
  2. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    552
    Karl Seguin [MVP]
    Jun 16, 2006
  3. Alex van der Spek

    eval('07') works, eval('08') fails, why?

    Alex van der Spek, Jan 8, 2009, in forum: Python
    Replies:
    6
    Views:
    1,469
    Bruno Desthuilliers
    Jan 8, 2009
  4. Liang Wang
    Replies:
    8
    Views:
    135
    Ben Morrow
    Feb 2, 2008
  5. Marc Girod

    to eval or not to eval?

    Marc Girod, Apr 19, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    161
    Marc Girod
    Apr 19, 2011
Loading...

Share This Page