You ought to use split if you don't know the number of "words" (and by words I'm assuming you mean space-delimited text) ahead of time. Heck, even if you do you should use split. For example:
# 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;
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.

Gary Blackburn
Trained Killer


In reply to Re: How can I place each "word" of a string in a varible if I don't know the length of the string? by Trimbach
in thread How can I place each "word" of a string in a varible if I don't know the length of the string? by anon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.