Mr. Shawn H. Corey wrote:
> On Mon, 2006-08-05 at 15:15 -0700, chen li wrote:
>>Both line codes work perfectly:
>>
>>my @new_array = map { split } @arry;
>>or
>>my @new_array = split ' ', "@arry";
>
> The second statement will work perfectly if every element has only one
> space character separating its components and has no leading or trailing
> spaces. A more general case would be to to split on whitespace:
>
> my @new_array = split /\s+/, "@arry";
>
> See `perldoc perlretut` and `perldoc perlre` for details.
Did you actually try it? I didn't think so.
$ perl -le'
my $string = q[ a b c d ];
print join "\t", map "<$_>", split " ", $string;
print join "\t", map "<$_>", split / /, $string;
print join "\t", map "<$_>", split /\s+/, $string;
'
<a> <b> <c> <d>
<> <> <a> <> <b> <> <c> <> <d>
<> <a> <b> <c> <d>
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>