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

Re: split in scalar context [was: Alarums and Excursions]

Thread Previous | Thread Next
From:
Yitzchak Scott-Thoennes
Date:
July 29, 2008 11:55
Subject:
Re: split in scalar context [was: Alarums and Excursions]
Message ID:
56090.71.212.97.166.1217357739.squirrel@webmail.efn.org
On Tue, July 29, 2008 10:38 am, Aristotle Pagaltzis wrote:
> * Abigail <abigail@abigail.be> [2008-07-29 12:45]:
>
>> On Tue, Jul 29, 2008 at 11:05:27AM +0100, Nicholas Clark wrote:
>>
>>> By which you mean remove the assignment to @_, and the
>>> warning, but keep the behaviour demonstrated above working?
>>
>> That would be quite useful, IMO, as the following secret
>> operator doesn't work for split:
>>
>> $words +=()= split;
>>
>>
>> It's one of the few places where perl incorrectly outsmarts the
>> programmer.
>
> Do note that you can still beat perl at its own game:
>
>
> $words += map 1, split;

You beat me.  I was going to say:

$words++ for split;

The "correct" answer would presumably be:

$words += () = split ' ', $_, 0;


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