Hi all,

I have two modules, interface1.pm and interface2.pm. They contain different sets of functions with the same names. Is there any way I can use both of them, and call the function I want by name, the module it uses being dependant on a variable?

For example, if I call the function terraform which is described in both interfaces and the variable $version is 1, then the interface1.pm version of terraform will be used. If version was 2, interface2.pm would be used.

That's what I'd like. Of course I'm noticing I can't load the two sets of functions without them overwriting each other, even if I say:

use interface1 (); use interface2 ();
I was hoping I could do that, and then use a combination of use and no when I wanted to switch "versions" in the program. But no, foiled at the outset.

I might be approaching this improperly, if so please nudge me in the right direction.

Thanks a lot!

GrandFather altered the title. Title was versioning


In reply to Calling same named functions from different modules by geckosan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.