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.

I have Perl 5.004 for DOS on my computer. I am not stuck on it. This is not what I use most of the time, but I do run it from time to time. There's nothing wrong with having an old perl interpreter. Right? Here's proof:

C:\>perl -v This is perl, version 5.004_02 Copyright 1987-1997, Larry Wall MS-DOS port Copyright (c) 1989, 1990, Diomidis Spinellis djgpp v2 port (jpl5003c) by Hirofumi Watanabe, 1996 djgpp v2 port (perl5004) by Laszlo Molnar, 1997 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5.0 source +kit. C:\>

When I fire up good old MS-DOS, this is the perl interpreter I use. So, if I write a perl script and want to run it in DOS mode, then it won't run unless I make sure it's compatible with Perl 5.004. If I can write a perl script that is compatible with DOS and I know how to do it, then why not do it? I want my scripts to be compatible.

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!

Wow. That's good to know! Thank you for mentioning this!

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

Yes, I overcame that problem by simply creating a "warnings.pm" file in the LIB directory, so perl 5.004 thinks it's there. and doesn't give me an error anymore. So, I just want perl to shut up and run my scripts without any errors. I've achieved that. And as I said, the only thing that makes my scripts incompatible now is that I use open() with 3 args instead of 2. But using 2 args is no biggie. I can do that easily. which means my scripts are compatible all the way back to DOS era! Hehe

"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?)

The first programming language I learned was QBASIC. To open a file in QBASIC, you use numbers as file handles. See example here:

OPEN FILENAME1$ FOR INPUT AS #1 OPEN FILENAME2$ FOR OUTPUT AS #2 LINE INPUT #1, ROW$ PRINT #2, ROW$ CLOSE #2 CLOSE #1 END

I don't know about you, but the above code looks very familiar to me, because I have written this a lot. The fact that I can use a number as a file handle in Perl is VERY COOL. It makes my perl code look more familiar to me. :)


In reply to Re^3: First attempt at bringing in file for input/output by harangzsolt33
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.