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

Re: scalar sort $scalar

Thread Previous | Thread Next
Ed Avis
July 9, 2015 10:22
Re: scalar sort $scalar
Message ID:
Abigail <abigail <at>> 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 <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About