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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |