Seems like a query similar to How [to] include a file in Perl script by OP, resulting quite possibly in the same responses.
Forgot to mention earlier ... There can be more reasons for failure to open a file other than a non-existing file: permission errors, running out of file descriptors, and possibly others (that I do not know about). Therefore, instead of ...
my $file = 'file-name';
if( open(HANDLE, $file) )
{
...
}
else
{
print "No such file or directory\n";
}
... should use $! (aka $OS_ERROR, $ERRNO) in printing of a message ...
if ( open my $handle, '<', $file )
{
...
}
else
{
print $!, "\n";
#warn "Cannot open file '$file' to read: $!";
}
... so that you can have as close to the real reason for open failure as possible.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|