You are really, really lucky that your script just dies (and is not silently corrupting something).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.