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

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

Thread Previous
From:
Ed Avis
Date:
July 25, 2014 07:01
Subject:
Re: New feature proposal : <<>> to disable magic open of ARGV
Message ID:
loom.20140725T085035-920@post.gmane.org
Abigail <abigail <at> abigail.be> writes:

>Disabling this with a feature means, you're disabling it with something
>you don't see.
>
>   while (<>) {
>       ...  # Magic open or not?
>   }

I would agree, except that 90% of the time someone who programs while (<>)
doesn't consciously intend any kind of magic.  It has always been promoted
as the standard way to read files given on the command line.  Practically
speaking it is simpler to change it to be safe rather than change the
accumulated weight of tutorial material, existing code and common practice.

(And yes, I know that the Camel does talk about the neat tricks you can do
passing pipe expressions on the command line, but that hasn't really sunk in
as well as it should.)

But, if there is a hidden gotcha that many programmers do not consider,
adding a pragma to turn it off is just about the worst way to fix it.  Only
those who already know to take precautions will bother with the pragma.
Perl needs to move towards a state where the default behaviour is safe,
with magic enabled for those who request it.

A new (<<>>) construct doesn't do much to fix existing code, but it doesn't
break it either (for programs where the magic opening is desired and
documented behaviour), and at least it is unambiguous.

-- 
Ed Avis <eda@waniasset.com>




Thread Previous


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