Perl Monk, Perl Meditation | |
PerlMonks |
RE: Re: Subroutine questionby jreades (Friar) |
on Sep 18, 2000 at 22:29 UTC ( [id://33004]=note: print w/replies, xml ) | Need Help?? |
The basic point is that it is poor programming style (and ineffecient to boot) to have two subroutines that essentially do the exact same thing. From my standpoint as someone who has learnt to code that painful way (is there any other), I've developped the standard methodology that if I have duplicated code (or code that closely duplicates functionalities I've used elsewhere) then I need to go back and look at condensing the duplicates into a single subroutine. In this case, then, you might start by changing the subroutine as follows:
Notice, however, that there are some areas that could use some more work:
And finally, you'd call this script by doing the following:
Which, of course, using the heuristic of duplicated code = BAD, could be condensed into a single array of arrays that are looped over and passed in in turn. Does that help?
In Section
Seekers of Perl Wisdom
|
|