M. Kristall wrote:
> chen li wrote:
>>>> I have an arry like this:
>>>>
>>>> @arry=('AA bb','BB','CC AG')
>>>>
>>>> How do I turn it into new array like this:
> TMTOWTDI
>>>>
>>>> @new_array=('AA','bb','BB','CC','AG')
>>> my @new_array = split ' ', "@arry";
>>
>> Both line codes work perfectly:
>>
>> my @new_array = map { split } @arry;
>> or my @new_array = split ' ', "@arry";
> or
> for (my $i = 0; $i < @arry; $i++) {
> splice (@arry, $i, 1, split (' ', $arry[$i], 1));
> }
How does that populate the @new_array variable? "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.)
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>