in reply to Are strings lists of characters?
I had to think very long and hard for a case where having strings be character arrays would offer syntatically superior, more concise ways of expressing than using substr. I have finally come up with something. Consider this:
This would be very awkward to achieve with substrs, particularly for more complex examples. (Bioinformatics might be an area where such could be useful.) But thanks to /(.)/sg expressiveness doesn't suffer much even here; the only concern I see is efficiency, if you do this a lot. But if that really is a probably, use a class with a real array in its guts and an overloaded stringification operator would probably suffice. And that one is downright trivial, something like: sub stringify { local $"; "@{$_[0]}" }my @string = "hubris" =~ /(.)/sg; @string[0,2,5] = "etv" = ~ /(.)/sg; print reverse @string; __END__ virtue
Assignment needs to be overloaded too, I guess, and would be slightly less trivial.
All in all, I conclude that there's not much need for such a feature at the language level. A module should suffice.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Are strings lists of characters?
by gjb (Vicar) on Oct 21, 2002 at 16:00 UTC | |
by Aristotle (Chancellor) on Oct 21, 2002 at 18:02 UTC |