Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(bbfu) Re: Spliting letters in a string

by bbfu (Curate)
on May 08, 2001 at 02:04 UTC ( [id://78679]=note: print w/replies, xml ) Need Help??


in reply to Spliting letters in a string

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
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://78679]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-19 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found