XP is just a number | |
PerlMonks |
Re: Empty strings after split /(\W)/by Anonymous Monk |
on Oct 01, 2014 at 21:09 UTC ( [id://1102591]=note: print w/replies, xml ) | Need Help?? |
Think of it like a really simple CSV file*. Your separator character is \W. To make it easier to think about, replace all \W with a comma, and your input string is "Hello,,World,,,". split /,/, "Hello,,World,,," gives you the list "Hello", "", "World" (trailing empty fields are stripped as documented). What you're asking split to do when you say split /(,)/, "Hello,,World,,," is keep the separator character in the list of return values (also the empty fields between separators aren't stripped). Hence:
* Just for the sake of discussion, we all know we should be using Text::CSV instead of split ;-)
In Section
Seekers of Perl Wisdom
|
|