ozgurp has asked for the wisdom of the Perl Monks concerning the following question:
1. Make the bodies of my if statements into procedures.
2. Have, at the very beginning of my program, my if statements. Rather than have them execute the procedures, have them build an array of procedure references.
3. In the body of my script, for each row of data, call each procedure in the array.
Instead of having following code:
I could have for example C B A R if statement in the while loop because the user selects only CBAR.while(<FH>){ if($_ =~ C B A R){ do something This bit is not the same for all elements and it is average 100 +lines long } if($_ =~ Q U A D){ do something This bit is not the same for all elements and it is average 100 +lines long } if($_ =~ C R O D){ do something This bit is not the same for all elements and it is average 100 +lines long } if($_ =~ C B E A M){ do something This bit is not the same for all elements and it is average 100 +lines long } if($_ =~ C E L A S 1){ do something This bit is not the same for all elements and it is average 100 +lines long } ... }
while(<FH>){ if($_ =~ C B A R){ do something This bit is not the same for all elements and it is average 100 +lines long } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I create a procedure
by sauoq (Abbot) on Jun 10, 2003 at 01:46 UTC | |
|
Re: How can I create a procedure
by educated_foo (Vicar) on Jun 10, 2003 at 01:52 UTC | |
|
Re: How can I create a procedure
by NetWallah (Canon) on Jun 10, 2003 at 04:39 UTC | |
|
Re: How can I create a procedure
by aquarium (Curate) on Jun 10, 2003 at 01:56 UTC |