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

Re: scalar sort $scalar

Thread Previous | Thread Next
Ed Avis
June 30, 2015 13:29
Re: scalar sort $scalar
Message ID:
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 <>

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