Help - Search - Member List - Calendar
Full Version: Run a subroutine, then replace subroutine and run again
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Sorry, but I have two subroutines with the same name which is fine because I have not had a need to use the hashes which these two similar subroutines created.

How do I run the subroutine and generate my set of hashes, then replace the sub with the other and run again, but into different hashes.

What I have is: a) use termareg and b) use termregall

which is called by termareg( ... ); # where ... are the hashes passed

Been setup like this for over 2.5 years and this is the first time I need the data from both at the same time. I would rather not rename since that would require other processing changes in a production environment.


Any questions and/or problems, please let me know.

Thanks!

Wags ;)
WGO: x2224



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************

Jeff 'japhy' Pinyan
On Jun 27, Wagner, David --- Senior Programmer Analyst --- WGO said:

QUOTE
Sorry, but I have two subroutines with the same name which is fine
because I have not had a need to use the hashes which these two similar
subroutines created.

How do I run the subroutine and generate my set of hashes, then
replace the sub with the other and run again, but into different hashes.

Is the problem that foo1() and foo2() *populate* a hash of a specific
name? Like this:

sub foo1 {
%something = (...);
}

sub foo2{
%something = (...);
}

If that's the case, you could do:

foo1();
my %copy = %something;
foo2();

Now you have %copy and %something. Is that the situation?

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart

Dave Gray
On 6/27/05, Wagner, David --- Senior Programmer Analyst --- WGO
<[Email Removed]> wrote:
QUOTE
Sorry, but I have two subroutines with the same name which is fine because I have not had a need to use the hashes which these two similar subroutines created.

How do I run the subroutine and generate my set of hashes, then replace the sub with the other and run again, but into different hashes.

What I have is:  a) use termareg and b) use termregall

which is called by termareg( ... ); # where ... are the hashes passed

Does 'use'-ing the modules call the subroutines that generate the
hashes? If so, you could 'use' the first one and then 'require' the
second one, so you can control when the second subroutine gets
declared (runtime as opposed to compile time). You'll get a
'subroutine redefined' warning, but it should work fine.

Jeff 'japhy' Pinyan wrote:
QUOTE
On Jun 27, Wagner, David --- Senior Programmer Analyst --- WGO said:

Sorry, but I have two subroutines with the same name which is fine
because I have not had a need to use the hashes which these two
similar subroutines created.

How do I run the subroutine and generate my set of hashes, then
replace the sub with the other and run again, but into different
hashes.

Is the problem that foo1() and foo2() *populate* a hash of a specific
name?  Like this:

sub foo1 {
%something = (...);
}

sub foo2{
%something = (...);
}

If that's the case, you could do:

foo1();
my %copy = %something;
foo2();

Now you have %copy and %something.  Is that the situation?

No, they are passed references. I received an earlier email saying to do run 1 and the do a require and then I can run with the second one.

Thanks for the input though.

Wags ;


*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************

Dave Gray wrote:
QUOTE
On 6/27/05, Wagner, David --- Senior Programmer Analyst --- WGO
<[Email Removed]> wrote:
Sorry, but I have two subroutines with the same name which
is fine because I have not had a need to use the hashes which these
two similar subroutines created.

How do I run the subroutine and generate my set of hashes,
then replace the sub with the other and run again, but into
different hashes.

What I have is:  a) use termareg and b) use termregall

which is called by termareg( ... ); # where ... are the
hashes passed

Does 'use'-ing the modules call the subroutines that generate the
hashes? If so, you could 'use' the first one and then 'require' the
second one, so you can control when the second subroutine gets
declared (runtime as opposed to compile time). You'll get a
'subroutine redefined' warning, but it should work fine.

I must be missing something because the code is not doing what I expected but then I may have wrong expectations.

Code is something like:

use sub1;
.... # other code

my ( %MH1, %MH2 ) = ();
sub1( %MH1, %MH2);

if ( true ) {
require sub1a; # called as sub1
my ( %MH3, %MH4, %MH5 ) = ();
sub1( %MH3, %MH4, %MH5 );
}

What I see is require overlaying sub1 before the the first call of sub1.

What am I doing wrong or what am I not understanding as to how to overlay a subroutine, but when I want it overlaid and not just when Perl says it should be.

Thanks.


*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************

Wagner, David --- Senior Programmer Analyst --- WGO wrote:
QUOTE
Dave Gray wrote:
On 6/27/05, Wagner, David --- Senior Programmer Analyst --- WGO
<[Email Removed]> wrote:
Sorry, but I have two subroutines with the same name which
is fine because I have not had a need to use the hashes which these
two similar subroutines created.

How do I run the subroutine and generate my set of hashes,
then replace the sub with the other and run again, but into
different hashes.

What I have is:  a) use termareg and b) use termregall

which is called by termareg( ... ); # where ... are the
hashes passed

Does 'use'-ing the modules call the subroutines that generate the
hashes? If so, you could 'use' the first one and then 'require' the
second one, so you can control when the second subroutine gets
declared (runtime as opposed to compile time). You'll get a
'subroutine redefined' warning, but it should work fine.

I must be missing something because the code is not doing what I
expected but then I may have wrong expectations.

Code is something like:

use sub1;
....  # other code

my ( %MH1, %MH2 ) = ();
sub1( %MH1, %MH2);

if ( true ) {
    require sub1a;    # called as sub1
    my ( %MH3, %MH4, %MH5 ) = ();
    sub1( %MH3, %MH4, %MH5 );
}

What I see is require overlaying sub1 before the the first call of
sub1.

What am I doing wrong or what am I not understanding as to how to
overlay a subroutine, but when I want it overlaid and not just when
Perl says it should be.

Thanks.

As we say, "I have found the enemy and he is me!!" Sorry, but when I initially was doing the work I had two use statements at the front because I thoguht they had different sub names. I inadvertently left both in. Reason not working. I found when I had commented out the section of code ( between a =head1 and =cut) and it still said that the subroutine had been renamed. At that point, I knew something was out of wack and it was!!! ;))

Thanks for listening and now back to our regular programming.

Wags ;)


*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.