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


Thread Next
Matt Diephouse
March 20, 2005 20:45
Message ID:
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

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