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

Re: Alarums and Excursions (was [perl #2783] Security of ARGVusing 2-argument open)

Thread Previous | Thread Next
From:
Abigail
Date:
July 28, 2008 09:08
Subject:
Re: Alarums and Excursions (was [perl #2783] Security of ARGVusing 2-argument open)
Message ID:
20080728160841.GI30221@almanda
On Mon, Jul 28, 2008 at 09:58:42AM +0100, Ed Avis wrote:
> Mark Mielke <mark@mark.mielke.cc> wrote
> 
> [magic handling of special characters in <>]
> 
> >I think the only 
> >part I'm missing to be 50% + 1 convinced personally is a 
> >survey or some other measure on how widely used these features 
> >are.
> 
> I think this is mostly unknowable.  We've done a little survey here and IIRC the answers were
> 
> - I might have used it once on Windows (me).
> 
> - You can use the trailing newline stripping for some idiom where you set ARGV from input data without chomping.
> 
> - I expect tchrist will give examples of where he likes it and uses it.


There was an official survey? I certainly have used magical 2-arg open more
than once, although I cannot recall whether that was in combination with '<>'.

> But mostly, even those who dislike the idea of making <> un-magic were not really using the special features except for golfing.  And people on this list are about the most expert perl users you will find.  If even we don't use it, chances are that hardly anyone else does.


But you don't know. It's just the putting your finger in the wind,
querying the handful of people who happen to read this thread. The
fast majority of Perl programmers doesn't read p5p. In fact, the fast
majority of the Perl programmers out there doesn't read any mailinglist,
nor do they participate in anyway in the "Perl community". Only a tiny
minority has code on CPAN.


> You suggested that an 'ordinary user' of a program that happens to be written in perl and using <> might start to rely upon the magic behaviour.  But this seems to me unlikely if the magic is not mentioned in the program's documentation (and it never is).  Only someone who already knew perl would do so.  (Indeed, someone who knew more about the behaviour of <> than the original programmer knew, or at least documented.)  And most of the time, I would expect people to prefer the shell's standard facilities for redirecting input from a pipeline, which work with all programs.


The shell is only an option if the shell is involved. And even if there's a
shell, such constructs aren't always that portable.


I remain of the opinion that p5p has always been quite careful about breaking
backwards compatability, bending over backwards to avoid breaking even the
most obscure construct. I think 'while (<>)' should keep doing what it has
done for longer than I can remember (that is, using 2-arg open).

And I welcome any construct that uses 3-arg open.

Now, for some shedcolouring: instead of using <<>>, why not allow a
listing of IO layers between '<' and '>', which would cause the construct
to automatically open the files with the listed layers? That is,

    while (<:utf8>) {
        # Opens files like 'open $fh, "<:utf8", "filename"'
    }

A lone : could indicate using 3-arg open, without using any PerlIO layers.

    while (<:>) {
        # Open files like 'open $fh, "<", "filename"'
    }



Abigail

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