No such thing as a small change | |
PerlMonks |
Re: Re: Re: Improvement on script needed.by Not_a_Number (Prior) |
on Sep 08, 2003 at 20:08 UTC ( [id://289852]=note: print w/replies, xml ) | Need Help?? |
There are all sorts of problems with this code. You seem to have copied snippets from various answers to your question into your code without understanding any of them. I suggest you spend some considerable time studying the resources listed here. However, to return to your immediate problems, let's look, for example, at the number of times you use open in your code. Lines 3-7 are as follows:
Why on earth do you want reopen (for reading) the same file that you've just closed, once you've already read it into an array? As perl is forgiving, you can needlessly open (and/or close) the same file as many times as you want without it complaining, but... More importantly, the third time you use open is inside a while loop:
Apart from the fact that - at least for clarity's sake - you shouldn't be using the same filehandle for two completely different files (and that in any case DATA is not a particularly good filehandle to choose...) - try to envision what the above is doing. As the open line is inside a loop, it will, for each iteration of the loop, open 'test4.txt' for overwriting. If you don't understand that, try running this:
as compared with this:
dave
In Section
Seekers of Perl Wisdom
|
|