develooper Front page | perl.perl5.porters | Postings from September 2014

Re: New feature proposal : <<>> to disable magic open of ARGV

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
September 30, 2014 06:33
Subject:
Re: New feature proposal : <<>> to disable magic open of ARGV
Message ID:
CAMoYMM9i1+giX0Oi32g9=bihrMdNqfvCQX5FGUtWxU9VHNk9yQ@mail.gmail.com
On 29 July 2014 23:54, Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
> * Rafael Garcia-Suarez <rgs@consttype.org> [2014-07-24T11:51:40]
>> I believe that this was discussed here some years ago, and that this
>> was suggested by TomC. Anyway, I pushed a patch on rgs/nomagicopen.
>> The patch is incomplete as it lacks docs and tests. I welcome feedback
>> on the intent of the feature.
>
> I'm still not crazy about the one-off syntax addition, but I think that it's
> the best we're going to see without setting an unrealistic bar for a new,
> generic feature.  If we ever *do* get <> adverbs, we can call this sugar for
> one or blah blah blah it doesn't matter that much right now. :-)
>
> While my heart wants -n to be safe, my conscience tells me that we'll break
> enough (bizarre, to my mind (except maybe regarding "-")) expectations that it
> isn't worth doing.  Probably we want -P and -N for safe opening.
>
> I am gratified to see that <<X>> fails for any X, as you've only made the
> literal construct <<>> iterate.  Awesome.  I think we're going to want a better
> error message, if possible, though, than:
>
>   ~/code/perl5$ ./perl -e 'while (<<ARGV>>) { print }' 'ls |'
>   Can't find string terminator "ARGV" anywhere before EOF at -e line 1.
>
> Something roughly like "safe <<>> operator meaningless on concrete filehandles"
> — that's not right, but you get the idea.
>
> I don't think I have any further thoughts on it.

I have now merged this in blead, with more tests, and docs by Peter Martini
and myself. I also added tests for the $ARGV variable, that was not tested.

I'm not too sure about the error message; it's not totally trivial to
change, since
a script like this one, for example, will print "8":

print <<FOO>> 1;
16
FOO

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About