Apr 14, 2002, 7:37 AM
Post #7 of 12
But I do prefer your method of splitting on \s instead of the literal space ' '.
I do prefer Kanji's method, because (from the split manpage) ...
As a special case, specifying a PATTERN of space
(`' '') will split on white space just as `split'
with no arguments does. Thus, `split(' ')' can be
used to emulate awk's default behavior, whereas
`split(/ /)' will give you as many null initial
fields as there are leading spaces. A `split' on
`/\s+/' is like a `split(' ')' except that any
leading whitespace produces a null first field. A
`split' with no arguments really does a
`split(' ', $_)' internally.
So instead of splitting at every whitespace, Kanji's version splits at every sequence of whitespace, which means he really gets a list of separated words.
At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."