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 ',' , @{$_}; }
In reply to Re^3: Why does split on /./ not split the string?
by parv
in thread Why does split on /./ not split the string?
by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |