in reply to How can I place each "word" of a string in a varible if I don't know the length of the string?
The second example gives you an array filled with all the words in the sentence, in order. Now, if your question is how to put all the words into individually named scalar variables the answer is you can't. I mean, logically, how can you put n number of words into n number of scalars when n is unknown? You can't. That's why God invented the array, so you don't have to know. @words will be exactly as long as the number of words in your sentence, and you can get to each one whenver you wish, and have your nasty little way with them.# Yes, I know how many "words" there are. ($word_one, $word_two, $word_three) = split " ", $sentence; # No, I don't know how many words there are. @words = split " ", $sentence;
Gary Blackburn
Trained Killer
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How can I place each "word" of a string in a varible if I don't know the length of the string?
by Beelzebub (Initiate) on Dec 05, 2000 at 19:16 UTC |