replacing modules?

Discussion in 'Perl Misc' started by Torsten Mohr, Mar 7, 2004.

  1. Torsten Mohr

    Torsten Mohr Guest

    Hi,

    if i load a module by something like:

    use module;

    then i could also just load all the functions in module.pm
    into my own script and everything is fine.
    This works for some modules.

    But how for example do i replace:

    use vars qw/$some $list $of $variables/;

    What else do i need to look for if i want to replace some
    modules?


    Best regards,
    Torsten.
    Torsten Mohr, Mar 7, 2004
    #1
    1. Advertising

  2. Torsten Mohr

    Anno Siegel Guest

    Torsten Mohr <> wrote in comp.lang.perl.misc:
    > Hi,
    >
    > if i load a module by something like:
    >
    > use module;
    >
    > then i could also just load all the functions in module.pm
    > into my own script and everything is fine.
    > This works for some modules.


    It works better if you put the text of the foreign module into a BEGIN
    block where the "use" statement used to be. Immediately following,
    add another block

    BEGIN { Module->import( ...) if Module->can( 'import') }

    The dots represent the arguments to the former "use" statement.

    > But how for example do i replace:
    >
    > use vars qw/$some $list $of $variables/;


    There is no general recipe. This statements is needed to make the
    module work if it is *not* part of your file. To replace it, you
    must understand why it is there and replace it with something that
    does the same thing in the new situation. It may need no replacement
    at all.

    > What else do i need to look for if i want to replace some
    > modules?


    Start with the pair of BEGIN blocks sketched above. Then debug it:
    run it and repair what's broken.

    Anno
    Anno Siegel, Mar 7, 2004
    #2
    1. Advertising

  3. Also sprach Anno Siegel:

    > Torsten Mohr <> wrote in comp.lang.perl.misc:
    >> Hi,
    >>
    >> if i load a module by something like:
    >>
    >> use module;
    >>
    >> then i could also just load all the functions in module.pm
    >> into my own script and everything is fine.
    >> This works for some modules.

    >
    > It works better if you put the text of the foreign module into a BEGIN
    > block where the "use" statement used to be. Immediately following,
    > add another block
    >
    > BEGIN { Module->import( ...) if Module->can( 'import') }


    You can even drop the 'if' altogether. The 'import' method is special in
    that perl will silently turn 'Module->import' into a no-op if this
    method isn't inherited nor defined by Module.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval, Mar 7, 2004
    #3
  4. Torsten Mohr

    Anno Siegel Guest

    Tassilo v. Parseval <-aachen.de> wrote in comp.lang.perl.misc:
    > Also sprach Anno Siegel:
    >
    > > Torsten Mohr <> wrote in comp.lang.perl.misc:
    > >> Hi,
    > >>
    > >> if i load a module by something like:
    > >>
    > >> use module;
    > >>
    > >> then i could also just load all the functions in module.pm
    > >> into my own script and everything is fine.
    > >> This works for some modules.

    > >
    > > It works better if you put the text of the foreign module into a BEGIN
    > > block where the "use" statement used to be. Immediately following,
    > > add another block
    > >
    > > BEGIN { Module->import( ...) if Module->can( 'import') }

    >
    > You can even drop the 'if' altogether. The 'import' method is special in
    > that perl will silently turn 'Module->import' into a no-op if this
    > method isn't inherited nor defined by Module.


    Ah... I didn't know this. I must have falsely accused a few good
    programmers of sloppiness because of that :)

    Anno
    Anno Siegel, Mar 7, 2004
    #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. Remy Cool
    Replies:
    1
    Views:
    420
    Remy Cool
    Aug 27, 2003
  2. Tobiah
    Replies:
    2
    Views:
    306
    Tobiah
    Sep 14, 2003
  3. Ben Weintraub

    Disabling modules using Modules/Setup

    Ben Weintraub, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    344
    Ben Weintraub
    Sep 9, 2006
  4. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    290
    Peter Peyman Puk
    Mar 19, 2010
  5. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    259
    Chris Hohmann
    Apr 11, 2005
Loading...

Share This Page