P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi, you have a working solution by now, but just a few comments on some mistakes in your code, to help you progressing:
First it is a very bad idea to open the same file repeatedly within a while loop. This is very inefficient. Whenever you have something like that, read the file with the elements to be found prior to the main loop and store these items in memory (an array, a hash, a regex, a string, something, whatever). Second, when you read F3, you need to chomp the line to remove the trailing end of line. Else you will be looking for "c_c\n", not "c_c", so that you won't find it. Third, this code line: is reading only one line from the file (the first one). So that if the other errors were corrected, you would still be able to catch only the first intemof the file. Finally, this is not an error, your code will work on that, but it is considered better practice to use the so-called three-argument syntax for opening a file and to use lexical file handles: Note that I also added a message to the die statement: 1. saying what the problem is ("Could not open..."), 2. telling which file the script could not open, and 3. displaying the error message reported by the OS (the $! special variable). Believe me, this helps when you have scripts opening dozens of files. I hope this helps. Update: Corrected a couple of typos and added a little bit of further explanations.
Je suis Charlie.
In reply to Re: How to read the regular expression from another file?
by Laurent_R
|
|