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

Re: scalar sort $scalar

Thread Previous | Thread Next
From:
Ed Avis
Date:
June 30, 2015 13:29
Subject:
Re: scalar sort $scalar
Message ID:
loom.20150630T152353-954@post.gmane.org
It would sometimes be useful to treat a string as a list of characters and use
the list operations such as reverse and sort.  (Sometimes the same operation
already has string and list variants, as substr/splice and length/scalar(@_).)
But this would need to be explicit - as others mention, doing an implicit
split opens a can of worms about the definition of a character.

How about making split an lvalue?

    push split(':', $str), 'a', 'b';  # appends :a:b to nonempty string,
                                      # or sets empty string to a:b

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

Sometimes I have also wished to use string operators such as index() and
regular expressions on lists, though what the syntax for that would be I
have no idea.

-- 
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