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

Re: [PATCH] Remove implicit split to @_

Thread Previous | Thread Next
From:
Abigail
Date:
July 10, 2009 09:04
Subject:
Re: [PATCH] Remove implicit split to @_
Message ID:
20090710160402.GH10063@almanda
On Fri, Jul 10, 2009 at 11:55:16AM -0400, Chas. Owens wrote:
> On Fri, Jul 10, 2009 at 10:39, Peter Scott<Peter@psdt.com> wrote:
> > On Thu, 09 Jul 2009 21:28:14 -0700, Chip Salzenberg wrote:
> >
> >> This is an amusing discussion.
> >>
> >> The only problem that I observe with scalar split writing to @_
> >> implicitly is that it's an easy thing to do by accident and is almost
> >> never useful. Therefore, removing it seems a public service.
> >>
> >> I favor simply making it a compile-time error to use split in scalar
> >> context.  No problem with silently changing semantics and no more
> >> surprising behavior.  Everybody's happy.  (right?)
> >
> > I don't get it.  The docs say that scalar split returns the number of
> > elements.  That's useful and convenient, and more intuitive than some of
> > the alternative gyrations that have been suggested.  No one cares about it
> > shoving the contents in @_ or wants that to continue, especially since it
> > results in a warning.  So why can't we make it return the number of
> > elements without either populating @_ or generating a warning?
> >
> > --
> > Peter Scott
> >
> 
> The question is when do you want to know how many items a string can
> be split into without actually splitting the line?  If you are going
> to split the line, then you can ask the array how many elements it
> has.  I really don't see how scalar split (without splitting into @_
> or some other variable) is useful.  Why not have it split into @F?  @F
> is already used with -a, and is documented in perlvar, so it shouldn't
> be in use by anyone.


Since @F is *only* populated by the little used, and generally unknown -a,
I wouldn't count on it not being used.

I do see a use for split in scalar context returning the number of 
chunck which would have resulted - and I'd probably would have used
it in code were it not for the implicite population of @_.

Personally, I don't see much benefit for implicite populating any array,
whether it's @_, @F, @{^SPLIT}, or something else. I won't lose a night
of sleep over it if that was gone.

But I'm not a supporter of making split in scalar context an error.
Either replace it with something 'better' (for instance, just a count),
or leave it as is.


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