Front page | perl.perl6.language |
Postings from March 2005
Slices
Thread Next
From:
Matt Diephouse
Date:
March 20, 2005 20:45
Subject:
Slices
Message ID:
198c8738050320204550f9c89b@mail.gmail.com
Is it possible to assign to an array slice?
@array[0..4] = ( 0..4 ); # splice @array, 0, 5, 0..4
If so (and I'm hoping it is), is there an equivalent of Ruby's `[]=`
method? (Is there a way to define this behavior within my own
array-like classes?)
Can I use slice notation when dealing with strings?
say $string[-1]; # say substr($string, -1);
$string[0..2] = "Hello";
I know some people find strings-as-arrays too much like C, but I think
it can be convenient. (And I happen to think `splice` and `substr` are
really ugly.) I'm close to suggesting that we don't need `splice` and
`substr` at all, but there are times when it's more convenient to
specify with a starting point and a length than with a range.
--
matt diephouse
http://matt.diephouse.com
Thread Next