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

Re: scalar sort $scalar

Thread Previous | Thread Next
Ed Avis
July 10, 2015 06:10
Re: scalar sort $scalar
Message ID:
David Nicol <davidnicol <at>> writes:

>I optimistically understand Ed Avis's l-value split proposal to
>essentially be a rewrite rule

Well, I don't know if I would put it like that.  The original context was
whether the list operation 'sort' could be applied to scalars.  In a Unicode
word it is no longer obvious how to split a string into a list - and while
Perl does currently have 'reverse $scalar', the consensus was that this
isn't an example to be followed.

By making split an lvalue you make the transformation of string to list
explicit.  Thus

    split('', $str) = sort split('', $str);

But of course other list operations would need to work too:

    push split(':', $str), qw(a b c);
    my $x = pop(split(':', $str));

>clearly this would not be out of place on CPAN as something that exports
>an lvalue sub l_split($$; <at> ).

I was thinking that a tied array would probably make more sense.
It is more syntax but lets you do more things - in particular, you can
take a reference to a tied array.

Ed Avis <>

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