Before I explain what is happening I reiterate the things you should ALWAYS do (linuxer above already shows how to do it).
- use strict
- use warnings
- don't use backticks when you don't need the output
- don't use barewords as filehandles but lexical variables
- ALWAYS check the result of sys-calls
So what is happening in your script?
Contrary to what you might believe the `cd log-dir` does not change the working directory of the perl-script. Instead it forks off a shell which cds into that direcory, but it is only this shell that changes the direcory. After the backtick returns your script is still in the same dir. So the open fails because your are in the wrong dir. And now you are lucky because you try to read from an invalid file-handle which aborts the script. Imagine you had another file in your script's working dir named 'AppOsaEbcp1.log' - your script would use that rather then the one in the log-dir and you would not even notice it ...
In reply to Re: FILE reading question.(closed filehandle) issue in script
by morgon
in thread FILE reading question.(closed filehandle) issue in script
by ajay.awachar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |