I'm noticing I can't load the two sets of functions without them overwriting each other
. . .
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.

As you've noticed from the other responses, there are several ways to get something close to what you want. From the quotes above and your wording in general (talking about "versioning" for instance) it seems that maybe you have existing code that you want to change as little as possible but you want to pull in the new "version" of some functions as needed? Are you debugging or trying to test a new module piecemeal?

If that's the case, you might want to manually import the subs you want when you want them. Some aliasing as simple as:

{ no warnings 'redefine'; *foo = \&Interface1::foo; } print foo(); { no warnings 'redefine'; *foo = \&Interface2::foo; } print foo();
might do what you need. If you need a bit more flexibility, you could wrap that up in a sub like:
sub use_from { no strict 'refs'; no warnings 'redefine'; my $package = shift; *{ $_ } = *{ "$package\::$_" }{CODE} for @_; }
Which you could then use like:
use_from('Interface1', 'foo', 'bar'); foo(); bar() use_from('Interface2', 'foo', 'bar') foo(); bar();

For the sake of maintainability, you probably wouldn't want to leave this stuff in production code. But it can be handy during development.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Calling same named functions from different modules by sauoq
in thread 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.