Pathologically Eclectic Rubbish Lister | |
PerlMonks |
(bbfu) Re: Spliting letters in a stringby bbfu (Curate) |
on May 08, 2001 at 02:04 UTC ( [id://78679]=note: print w/replies, xml ) | Need Help?? |
I'm going to guess that the variable names being the same thing as the letters they contained was only a coincidence (although, perhaps an intentional one) and that you really meant that you just wanted each letter of the string to be in a separate variable. In that case, you don't need to bother with a hash: just use an array. Like so: @letters = split //, $string; If you did use a hash, you'd have to use keys to find out what letters were in the string and would end up getting back an array anyway. Plus, the letters would be irrevocably out of order. That doesn't seem like a useful solution any way around. Of course, my solution counts each single whitespace and punctuation character as a letter, which may not be what you want. <update>But then, so do all the other solutions presented so far. ;-P</update> I still think it's closer to what you meant, though. bbfu
In Section
Seekers of Perl Wisdom
|
|