in reply to Subroutine question
We can help you much better this way.
-- Casey I am a superhero.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Subroutine question
by jreades (Friar) on Sep 18, 2000 at 22:29 UTC | |
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? | [reply] [d/l] [select] |
|
RE: Re: Subroutine question
by Limo (Scribe) on Sep 18, 2000 at 22:24 UTC | |
1.I want this subroutine to be run as it reads and...
| [reply] [d/l] [select] |
by jreades (Friar) on Sep 21, 2000 at 07:49 UTC | |
Right, here's what we're saying:
This should do what you want as best as I can tell -- open a file and push into an array (either array 1 or array 2 depending on which iteration) any line that doesn't start with UNKNOW/unknow/#/NONE/none. Your lines
look very strange -- as someone else pointed out, if you're reading in the file line by line (which is what <FILE> implies) then the final split on \n is useless. In addition, you're only assigning the last value of @_ to @array1 (meaning the other values are lost) unless you've undefined $/, in which case you should just use my $file = <FILE> rather than the while loop. Hope this helps. | [reply] [d/l] [select] |