develooper Front page | perl.perl6.language | Postings from March 2005

string/list division

Thread Next
From:
Juerd
Date:
March 28, 2005 09:12
Subject:
string/list division
Message ID:
20050328171238.GU29322@c4.convolution.nl
It was a matter of time, of course, after my last thread.

How often do we want chunks of a string or list? And how often do we
abuse a temporary copy and substr/splice for that?

What if instead of

    my @copy = @array;
    while (my @chunk = splice @copy, 0, $chunksize) {
        ...
    }  # ^1

we could just write

    for @array [/] $chunksize -> @chunk { ... }

and instead of 

    my $copy = $string;
    while (defined(my $chunk = substr $copy, 0, $chunksize)) {
        ...
    }  # ^2

we could use

    for $string ~/ $chunksize -> $chunk { ... }

I think it'd make life much easier.

Of course, [/] is subject to the same discussion as the other thread,
and should perhaps be (/) or */.


Juerd

PS. http://tnx.nl/3689VBOF  # consistency gone mad (expires in 1 day)

^1 Yes, I know it can be made more efficient by using the "list
reference" trick, sub { \@_ }->(LIST).
^2 Same thing, but with \substr. Too bad there is only one LVALUE,
because you can't keep a reference around. Will this be fixed in P6?
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

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