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

Re: scalar sort $scalar

Thread Previous | Thread Next
From:
Ed Avis
Date:
July 9, 2015 10:22
Subject:
Re: scalar sort $scalar
Message ID:
loom.20150709T121713-809@post.gmane.org
Abigail <abigail <at> abigail.be> writes:


>>How about making split an lvalue?

>>    split(';', $str) = split(':', $str); # change separator

>And for changing separator, what's the benefit of using the proposed
>split() syntax over
>
>    $str =~ s/;/:/g;

I imagine that the split-as-lvalue assignment would fail at run time if any
of the list elements contained the ; character.  So you would not be able to
accidentally end up with more elements than you expected because of
insufficiently sanitized input.  If you assign to split(x, y) then that
split call would always return the same list you assigned to it, until the
string is modified.  That would make it slightly safer than s///.

-- 
Ed Avis <eda@waniasset.com>


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