M. Kristall wrote:
> John W. Krahn wrote:
>>> for (my $i = 0; $i < @arry; $i++) {
>>>     splice (@arry, $i, 1, split (' ', $arry[$i], 1));
>>> }
>>
>> How does that populate the @new_array variable?
> 
> Mine doesn't populate @new_array. It takes the original array and
> replaces it with the equivalent of everyone else's @new_array :-)
> (Or at least it's supposed to.)
> 
>> "split(' ', $arry[$i], 1)" is
>> exactly the same as "$arry[$i]" so you are replacing each element of
>> the array
>> with itself.  (A limit of 1 passes the string through unchanged.)
> 
> It's not my fault, blame mail client. When /I/ sent it, it said:
> 
> for (my $i = 0; $i < @arry; $i++) {
>     splice (@arry, $i, 1, split (' ', $arry[$i], 2));
> }
> 
> with the "2", not the "1" ;-)

If one of the elements of @arry contains "one two three" then using "2" will
add the two elements "one" and "two three" instead of the three elements
"one", "two" and "three" so you may still be left with elements containing
whitespace.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to