Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: On Backwards Compatibility and Bareword Filehandles

by haukex (Bishop)
on Jul 17, 2020 at 07:24 UTC ( #11119441=note: print w/replies, xml ) Need Help??


in reply to On Backwards Compatibility and Bareword Filehandles

I propose generalizing this to also allow open our $foo, ... (to explicitly open a global filehandle; remember TIMTOWTDI) and open state $foo, ...
use warnings; use strict; use feature 'state'; sub xyz { open state $foo, '<', '/tmp/foo' or die $!; chomp( my $bar = <$foo> ); close $foo; return $bar; } open our $foo, '>', '/tmp/foo' or die $!; print $foo "Hello\n"; close $foo; use Test::More tests=>1; is xyz(), "Hello"; # => PASS
the result will be a disaster reminiscent of Fahrenheit 451.

A variation on Godwin's law?

Replies are listed 'Best First'.
Re^2: On Backwards Compatibility and Bareword Filehandles
by jcb (Vicar) on Jul 17, 2020 at 23:38 UTC

    Thanks for pointing that out; I have updated the text. Is open state also conditional currently or will it replace an already-open handle?

    Godwin's law applies to hyperbolic comparisons; the reference to Fahrenheit 451 was to show that we are considering the first steps down a path that can lead to disaster. Removing code from programs is generally beneficial, but removing features from languages is almost always impoverishing. I could have cited Newspeak in 1984 as another example, but 1984 featured censorship imposed from a dictatorial top, while the censorship in Fahrenheit 451 was explained to have been more of a "crowd-sourced" phenomenon.

      Is open state also conditional currently or will it replace an already-open handle?

      Sorry, but I have to say: You already didn't do your due dilligence in the root node, and now you seriously expect me to do more of your work for you to support an argument I don't necessarily agree with? The internet being what it is, my troll-o-meter is going off.

        The internet being what it is, my troll-o-meter is going off

        Seems a bit harsh - this monk has continually provided quality advice, and in a manner that exudes earnestness and a genuine interest in the betterment of perl.
        Mind you, there's a bit going on here that I simply don't understand - especially posts by YourMother and LanX which appear to be angled towards provocation more than anything else.

        In terms of the original post of this thread, I have some sympathy.
        While I see potential pitfalls in the use of bareword filehandles, I don't regard that it is necessary to enforce defaults that forbid such usage.
        But then ... I don't really have anything against scalar filehandles and I'm a person who values pragmatism over integrity so I've just gone through the various test scripts of my cpan modules that use bareword filehandles, replacing them with scalar filehandles. (This is just so I'm prepared for what the future might bring.)
        It wasn't so hard ... just put a "$" in front of every bareword filehandle in the script, then declare a "my" for every one of those scalar filehandles at the beginning of the script.

        Cheers,
        Rob

        Fair enough; I missed that a feature that I had never tried to use was in fact already implemented. I have generally stayed with the 5.8 feature set because I am a big fan of backwards compatibility. I had forgotten to check if that generalization had already been done; mea culpa on that.

        I use open my $foo,... to open a file in a sub and open FOO,... for the same at top-level. Having not actually needed open our or open state, I did not know that those already exist.

      Godwin's law applies to hyperbolic comparisons

      It absolutely does not; and where it applies is extremely clear.

        If you wish to say that it applies to any Internet discussion, then it is strictly limited to comparisons to actual Nazis.

        Edit to add: Otherwise, Godwin's law becomes a cudgel with which nearly any discussion can be ended.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119441]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2020-09-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?