Luke Palmer <[EMAIL PROTECTED]> wrote:
> > Can I use slice notation when dealing with strings?
> >
> > say $string[-1]; # say substr($string, -1);
> > $string[0..2] = "Hello";
>
> No. I'm pretty sure that's the Right Thing, too. First, the "sixth
> element" in a string depends on how you're defining "element": byte,
> codepoint, grapheme, etc. Second, if you think you're using an array,
> and it's actually a string (even ""), then you'll be missing an error
> (though I understand that this is a weak argument). Third, we already
> have substr.
A while back, I think I suggested that .{bytes,points,graphs,chars} be
defined to return an array with the contents of the string split into
the indicated pieces. If this was a tied array which updated the
underlying string, would we get the OP's behavior for free?
say $string.chars[-1];
$string.points.splice(0, 2, "Hello"); # Or "Hello".points
--
Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]>
Perl and Parrot hacker
"I used to have a life, but I liked mail-reading so much better."