Multiple documents/files with same subroutine name

John Gigawatt <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <CAD5V-ovMH2eq_xKcFXOWTo48GuTqmTRgCjZdbjfHEYgtDb=bQA@mail.gmail.com>
Hi,

I have a question on the best way to handle having multiple "web pages"
having a subroutine with the same name in it.  I apologize in advance if I
use the wrong terminology.  I know there are issues with library modules
(use, etc) and also global variables.  I am assuming this is similar but
not sure the best way to handle.

Example:

test1.html
=====
#!/usr/bin/perl

testSub();

sub testSub
{
print "A";
}

test2.html
=====
#!/usr/bin/perl

testSub();

sub testSub
{
print "B";
}

If I run both of these over and over, ultimately I will start to see A's on
test2 and B's on test1, etc.  I do know about a "counter" issue within the
same subroutine -- but this is slightly different (at least from the
outside).

One solution obviously has been to make sure I have a custom name for every
subroutine... but that can get messy to maintain and is not perfect.

My thoughts are:

* Is there a way, when calling "testSub" to say "only call the testSub
local to this file"?

* Is there a way, when defining "sub testSub" to force it to be locally
scoped?  I believe the equivalent with variable is to say "our" rather than
"my"... but not sure how that would happen here.

I have not been able to find answers related to this specific issue -- only
to global variable issues and modules with conflicting names.

NOTE: I added "use warnings" but it did not provide any warning of this
issue.

Any help would be appreciated.

Thanks,
-John
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.