ROTFLMAO!
Sorry... not laughing at you, I was laughing at myself. I dowloaded your code and replaced the psuedocode with real code and boggled at why I kept getting errors to the effect of:

Undefined subroutine &B::just_print called at index.pl line 8.
and then it dawned on me what was going on.

When you are doing a use B; you are pulling in the B perl compiler and not getting the expected results. Anyway....

I modified your example and came up with the following:

# The main code: use A; use Blooper; foreach (0..1){ A::just_print("hi") if $_; B::just_print("hello") if not $_; } sub main_print(){ print @_; }
and
#A.pm package A; sub just_print{ print @_; main::main_print(); } 1;
and
#Blooper.pm package B; sub just_print { print @_; main::main_print(); } 1;
and when the code is run I get:
hellohi
as I would expect.

With all that in mind... what did you get for errors?


In reply to Re: calling functions with same names but in different modules depending on user input by blue_cowdawg
in thread calling functions with same names but in different modules depending on user input by Anonymous Monk

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.