in reply to Re^2: Why does split on /./ not split the string?
in thread Why does split on /./ not split the string?
Your pattern to split has capturing parentheses, which returns fields along w/ the delimiters; see perldoc -f split. Also, that [+] (mind you + here is just a plain plus sign) is useless as the string to be split lacks one.
Try this ...
my $string = 'one;two--three!!!'; my @list = split /([\W+])/ , $string; my @list2 = split /[\W+]/ , $string; my @list3 = split /([\W]+)/ , $string; my @list4 = split /[\W]+/ , $string; printf "Original: %s\n" , $string; print '-' x 9 , "\n"; foreach ( \@list , \@list2 , \@list3 , \@list4) { printf "%s\n" , join ',' , @{$_}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why does split on /./ not split the string?
by QM (Parson) on Dec 08, 2005 at 04:39 UTC |