if you pass 3 separate arguments to open(), then your program will not compile with earlier perl interpreters!

Perl 5.6, which introduced the 3-argument open, was released more than 18 years ago. AFAIK people being stuck on a Perl <5.6 should be pretty rare nowadays.

The two-argument form of open will invoke external programs if the first or last character of the filename is a pipe (|). If the filename is user-supplied, this is a security risk! Also, the two-argument form doesn't let you specify I/O layers such as ':encoding(UTF-8)'. That's why the three-argument form is recommended nowadays.

make sure that my code will be backwards compatible

Your code won't run on a Perl <5.6 because warnings wasn't introduced until 5.6.

Notice that you do not need to use a variable for file handle. You can use numbers.

What advantage does this have? (Especially to a beginner?)

I am not sure if Perl automatically closes the open file handle when we call die()

It does.


In reply to Re^2: First attempt at bringing in file for input/output by haukex
in thread First attempt at bringing in file for input/output by catfish1116

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.