Most likely you are not using strict. Your line makes little sense because open usually takes at least two parameters, the filehandle to be opened and the name of the resource to be accessed:

open(my $fh, "<", $file) or die("file open failed for '$file': $!");

That said, your code fails for me as expected:

X:\>perl -e "open($file) || die('file open failed');" file open failed at -e line 1. X:\>perl -e "open('xx') || die('file open failed');" file open failed at -e line 1.

I didn't know and haven't used the 1-argument form of open and for good reason, because that means action at a very large distance:

perl -e "$FILE='file_that_exists';open(FILE) || die('file open failed' +);"

In this case, the 1-argument form does not die because the file named in $FILE exists. But that is substantially different from your code.

Update You silently update your node. I consider that quite rude. Please mark updates to your node with <b>Update:</b> or something and don't overwrite the complete node.

Your new code fails for me as expected:

X:\>perl -w tmp.pl Name "main::IN" used only once: possible typo at tmp.pl line 5. Couldn't open `/tmp/test123' at tmp.pl line 5. X:\>type tmp.pl use strict; sub push_report { my $idx = shift; my $file= "/tmp/test123"; open(IN, $file) || die "Couldn't open `$file'"; }

Maybe you want to do more rigorous checks:

use strict; sub push_report { my $idx = shift; my $file= "/tmp/test123"; if (-e $file) { warn "'$file' exists"; } else { warn "'$file' does not exist"; }; if (-f $file) { warn "'$file' exists as a file"; }; if (-d $file) { warn "'$file' exists as a directory"; }; open(IN, $file) || die "Couldn't open `$file'"; }

In reply to Re: die not exiting Application by Corion
in thread die not exiting Application by mihirjha

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.