in reply to Split ( ) is Giving Me a Splitting Headache
What you probably want is
.my @Parts = split ' ', $Phrase;
Update: Also, note the subtle difference between split / / and split ' '. The latter is "magical" in that it drops leading whitespace, splits on runs of spaces instead of a single space. The following may demonstrate:
my $s = ' a b c '; my @p = split ' ', $s; print map { ">$_< " } @p; my @q = split " ", $s; print map { ">$_< " } @q; my @r = split / /, $s; print map { ">$_< " } @r; my @s = split /\s+/, $s; print map { ">$_< " } @s; __END__ >a< >b< >c< >a< >b< >c< >< >< >< >a< >< >< >< >< >b< >< >< >c< >< >a< >b< >c<
|
---|