Mailing List Archive

Multiple documents/files with same subroutine name
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
Re: Multiple documents/files with same subroutine name [ In reply to ]
On 08/01/2017 12:45 PM, John Gigawatt wrote:
> 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.


Johnie Giggawatt?

give me a break

--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
Re: Multiple documents/files with same subroutine name [ In reply to ]
On 08/01/2017 12:45 PM, John Gigawatt wrote:
> * 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.



do you know what package scopes are?


--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
Re: Multiple documents/files with same subroutine name [ In reply to ]
Hmm, that's not expected behavior with the code you're showing here. Are
you running this under ModPerl::Registry? It's supposed to generate a
unique package name for every file that prevents subs from colliding.

There are some things to watch out for when using subroutines in code you
run under Registry, but not what you're seeing here. The doc on those is
here:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html

- Perrin

On Tue, Aug 1, 2017 at 12:45 PM, John Gigawatt <john.gigawatt@gmail.com>
wrote:

> 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
>
>