Mr. Shawn H. Corey schreef: > chen li: >> 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.
Not so, see perldoc -f split. I believe I have pointed this out to you before. <quote> 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 behav- ior, 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. </quote> perl -e '$_=" 1 2 3 "; print "<", join( ":", split " "), ">"' <1:2:3> perl -e '$_=" 1 2 3 "; print "<", join( ":", split), ">"' <1:2:3> -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>