My code was well-formatted ;o) In case you want to use or copy code examples, please use the download link which should be shown below the code area. (I had to learn this lesson as well ;o))

If your open fails, the corresponding filehandle doesn't work and all following commands, which use that filehandle will run into errors or/and will print warnings (if enabled; which generally should be done).

By checking the success of the open, you can define what to do if it was successful, and what to do if not.

If you want to read from a file:

open my $fh, '<', $not_existent_filename; while ( my $line = <$fh> ) { print $line; } close $fh; print "END OF READ\n";

If warnings are enabled, you'll get a warning about "readline() on closed filehandle", but you cannot distinguish between this failure and an empty file.

If you recognize a delay by one single "or die ..." (or by the three I had in my previous example) in your script execution, I'm very impressed ;o)


In reply to Re: file test operations by linuxer
in thread file test operations by neutron

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.