Perl: the Markov chain saw | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It's been mentioned a couple times that it would be nice if strings acted like arrays of characters.
I agree that would be great for many things, but worry about the ramifications in the details. So, if we decide not to present a string as list magically or in a consistant manner across all the builtins, here is a light-duty idea. Right now, we split on empty to break into a list of chars. First we need split to specify u0,u1,u2, etc. Second, if split simply produced a lazy list rather than doing it all up front, that would satisfy the people who hate using split but wish it was more direct. Third, some syntactic sugar could be used, such as a special symbol or even a named sub that takes one argument. E.g. map { whatever } unravel($x). So, does the existance of lazy lists / generators take care of 90% of the issues that made people wish for strings-as-arrays? We can make a (lazy) array out of a string to suit the job, whenever we need. —John In reply to Are strings lists of characters? by John M. Dlugosz
|
|