runtime load of code

Discussion in 'Perl Misc' started by Alythh, Oct 28, 2003.

  1. Alythh

    Alythh Guest

    <this could be one of the most basic questions you've heard, but don't
    kick me on the teeth please, I've RTFM>

    I'm fairly new to Perl, and was trying to develop a program that
    1) reads an input file and:
    2) uses, to perform some tasks, some subroutines available in external
    files, those to be loaded defined by the input file e.g.:

    input file:
    ....
    aux_sub1.pl
    ....

    and in the code I call the functions defined in aux_sub1.pl

    What I don't understand if this is <exactly> the module mechanism, or
    if I have to use something new - I mean, those subs should be loaded
    in someway at runtime, while which modules I load is defined once and
    for all from the start, isntit?

    .... waiting for enlightenment, thanks!

    Alessandro Magni
     
    Alythh, Oct 28, 2003
    #1
    1. Advertising

  2. Alythh

    Anno Siegel Guest

    Alythh <> wrote in comp.lang.perl.misc:
    > <this could be one of the most basic questions you've heard, but don't
    > kick me on the teeth please, I've RTFM>
    >
    > I'm fairly new to Perl, and was trying to develop a program that
    > 1) reads an input file and:
    > 2) uses, to perform some tasks, some subroutines available in external
    > files, those to be loaded defined by the input file e.g.:
    >
    > input file:
    > ...
    > aux_sub1.pl
    > ...
    >
    > and in the code I call the functions defined in aux_sub1.pl
    >
    > What I don't understand if this is <exactly> the module mechanism, or
    > if I have to use something new - I mean, those subs should be loaded
    > in someway at runtime, while which modules I load is defined once and
    > for all from the start, isntit?


    What makes you think so? Look up "use" and "require" in perldoc
    and note the difference.

    Anno
     
    Anno Siegel, Oct 28, 2003
    #2
    1. Advertising

  3. It was a dark and stormy night, and Alythh managed to scribble:

    > <this could be one of the most basic questions you've heard, but don't
    > kick me on the teeth please, I've RTFM>
    >
    > I'm fairly new to Perl, and was trying to develop a program that
    > 1) reads an input file and:
    > 2) uses, to perform some tasks, some subroutines available in external
    > files, those to be loaded defined by the input file e.g.:
    >
    > input file:
    > ...
    > aux_sub1.pl
    > ...
    >
    > and in the code I call the functions defined in aux_sub1.pl
    >
    > What I don't understand if this is <exactly> the module mechanism, or
    > if I have to use something new - I mean, those subs should be loaded
    > in someway at runtime, while which modules I load is defined once and
    > for all from the start, isntit?
    >
    > ... waiting for enlightenment, thanks!
    >
    > Alessandro Magni


    For a start read http://perl.plover.com/FAQs/Namespaces.html

    Make sure you know the difference between packages & modules.

    gtoomy
     
    Gregory Toomey, Oct 28, 2003
    #3
  4. Alythh

    Alythh Guest

    OK, it works

    foreach $address (@addresses)
    {
    $mod = $modules{$address};

    require $mod;
    ....
    }

    .... it just complains about:
    Subroutine process_page redefined at ... line 20.
    Subroutine action_on_page redefined at ... line 48.

    but it's OK enough for me.

    thanks

    Alessandro Magni
     
    Alythh, Oct 28, 2003
    #4
  5. you are probably getting that because require will only retrieve the
    first copy of a subroutine and disregard the other subroutines with the
    same name

    Alythh wrote:

    >OK, it works
    >
    >foreach $address (@addresses)
    >{
    > $mod = $modules{$address};
    >
    > require $mod;
    >...
    >}
    >
    >... it just complains about:
    >Subroutine process_page redefined at ... line 20.
    >Subroutine action_on_page redefined at ... line 48.
    >
    >but it's OK enough for me.
    >
    >thanks
    >
    >Alessandro Magni
    >
    >


    --
    Regards,
    Dov Levenglick
     
    DOV LEVENGLICK, Oct 30, 2003
    #5
  6. Alythh

    Anno Siegel Guest

    [another of DOV's top-postings re-arranged]

    DOV LEVENGLICK <> wrote in comp.lang.perl.misc:
    > Alythh wrote:
    >
    > >OK, it works
    > >
    > >foreach $address (@addresses)
    > >{
    > > $mod = $modules{$address};
    > >
    > > require $mod;
    > >...
    > >}
    > >
    > >... it just complains about:
    > >Subroutine process_page redefined at ... line 20.
    > >Subroutine action_on_page redefined at ... line 48.

    >
    > you are probably getting that because require will only retrieve the
    > first copy of a subroutine and disregard the other subroutines with the
    > same name


    That is mere speculation, and it's wrong. In fact, the messages appear
    because require does *not* ignore later re-definitions of the same
    subroutine.

    Please don't post stuff you just made up of thin air.

    Anno
     
    Anno Siegel, Oct 30, 2003
    #6
  7. DOV LEVENGLICK <> vomits TOFU in our faces:

    > >Subroutine process_page redefined at ... line 20.
    > >Subroutine action_on_page redefined at ... line 48.


    > you are probably getting that because require will only retrieve the
    > first copy of a subroutine and disregard the other subroutines with
    > the same name


    Nonsense.

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
     
    Brian McCauley, Oct 30, 2003
    #7
    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. Satish
    Replies:
    0
    Views:
    958
    Satish
    Nov 13, 2003
  2. Isz
    Replies:
    0
    Views:
    927
  3. Hal Vaughan
    Replies:
    11
    Views:
    1,195
    Gordon Beaton
    May 22, 2006
  4. Carlos Ribeiro
    Replies:
    7
    Views:
    375
    Michael Hudson
    Nov 26, 2004
  5. Gnep
    Replies:
    0
    Views:
    309
Loading...

Share This Page