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

Re: scalar sort $scalar

Thread Previous | Thread Next
From:
Ed Avis
Date:
July 10, 2015 06:10
Subject:
Re: scalar sort $scalar
Message ID:
loom.20150710T080424-723@post.gmane.org
David Nicol <davidnicol <at> gmail.com> 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 <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