"Re-run script" sub

B

bogdan_czyz

Hi,

I'm trying to write a script that has a sort of "re-run itself"
procedure. I'm trying to figure out how to put that sort of code within
a script. For example:


## Begining of the script
&Startup;
.....
&sub1;
if ( &sub3($param) =~ /good/ ){
&sub2;
}else{
&sub_emerg;
&rerun_everything;
}
.....
&sub4;
## End of the script

What would the best approach be to make script to re-run (run
everything from &Startup) from within rerun_everything sub?
Thanks in advance for any suggestions,
Bogdan
 
A

A. Sinan Unur

(e-mail address removed) wrote in @c13g2000cwb.googlegroups.com:
I'm trying to write a script that has a sort of "re-run itself"
procedure.

What is a 'sort of re-run itself procedure'? I am asking very seriously.
## Begining of the script

use strict;
use warnings;
&Startup;

You should not use the ampersand notation to call subroutines unless you
specifically need the features associated with it. That means, if you
don't know what those features are, call your subroutines simply as:

startup();

(see perldoc perlsub for more information).

It seems to me that you have a ton of global variables which each
successive subroutine acts on. Not really a good idea.
....
&sub1;
if ( &sub3($param) =~ /good/ ){
&sub2;
}else{
&sub_emerg;
&rerun_everything;
}
....
&sub4;
## End of the script

What would the best approach be to make script to re-run (run
everything from &Startup) from within rerun_everything sub?

I have no idea what best is because I do not know what you are trying to
do. Does the following help?

#! perl

use strict;
use warnings;

$| = 1;

run() while 1;

sub startup { 'startup' }
sub sub1 { 'sub1' }
sub sub2 { 'sub2' }
sub sub3 { 'sub3' }
sub teardown { 'teardown' }

sub run {
print startup(), sub1(), sub2(), sub3(), teardown();
}

__END__

Sinan

__END__
 
T

Tad McClellan

I'm trying to write a script that has a sort of "re-run itself"
procedure. I'm trying to figure out how to put that sort of code within
a script. For example:


## Begining of the script
&Startup;
Startup();


sub1();


sub2();


sub_emerg();


rerun_everything();


&sub4;

sub4();


see

perldoc perlsub

for why.

What would the best approach be to make script to re-run (run
everything from &Startup) from within rerun_everything sub?


But it in a block, redo() the block:


BEGIN:
{ Startup();

...

redo BEGIN;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top