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

Re: scalar sort $scalar

Thread Previous | Thread Next
From:
Abigail
Date:
June 30, 2015 14:11
Subject:
Re: scalar sort $scalar
Message ID:
20150630141138.GB12147@almanda.fritz.box
On Tue, Jun 30, 2015 at 01:28:52PM +0000, Ed Avis wrote:
> 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


While I kind of see what you mean by the latter, I'm just wondering what

    split (/foo|bar/, $str) = split (/\s+/, $str);

or

    split (/foo|bar/, $str) = 17;

should do. 

And for changing separator, what's the benefit of using the proposed
split() syntax over

    $str =~ s/;/:/g;

?


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


I write them as:

    map {s/.../.../} @list

or

    s/.../.../ for @list;


Unless you want to do something else than I think you want.



Abigail

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