Well. I did test. I even installed an ancient perl 5.8.8 to make sure it hasn't been patched somewhere in between. You are right, I am wrong. I bow my head in shame.

But although I was wrong I still recommend to use variables for filehandles because a namespace collision may happen even though one carefully grepped the source code.


There's another issue and I misremembered it. I deliberately do something obviously stupid here to provoke the error.

#!/usr/bin/perl use strict; use warnings; open say, '<', '/etc/nsswitch.conf' or die "Unable to open file1: $!\n"; print "Filehandle is now open!\n"; print "1: " . <say>; exit;

This results in:

Filehandle is now open! 1: # /etc/nsswitch.conf

You'll probably also get a warning: 'Unquoted string "say" may clash with future reserved word at <script> line 8.' - something fishy is going on here. In a simple script you're likely to notice it. In a web- or GUI-driven application you probably don't.

Let's upgrade our perl and add a single line

use 5.010;

And suddenly the previously 'well-behaving' application goes boom.

Name "main::say" used only once: possible typo at <script> line 13. Use of uninitialized value $_ in say at <script> line 8. Can't use string ("1") as a symbol ref while "strict refs" in use at < +script> line 8.

What?!!

'use 5.10' exports 'say()' into your namespace. And suddenly open() does not open a filehandle 'say' but a function say(). Boom. Trying to debug that in a real world application may cause some serious headscratching - it's not that obvious anymore - especially if there's nobody warning you that library 'xyz' may accidently export your favourite filehandle name in the future.


In reply to Re^5: Bareword "SEEK_END" not allowed while "strict subs" in use (FH) by Monk::Thomas
in thread Bareword "SEEK_END" not allowed while "strict subs" in use by thanos1983

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.