in reply to calling functions with same names but in different modules depending on user input

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?

  • Comment on Re: calling functions with same names but in different modules depending on user input
  • Select or Download Code