my @chunks = split /(\s+)/, $str;
I prefer not to throw anything away in such cases:
my @chunk = split /(?<=\b)(?=\w)/, $str;Of course this complicates the code for reversing a word, as you have to keep the trailing whitespace at the end (which can be accomplished with sort if you're careful), but it also means that if the original has two spaces after a word, your final result will too!
In reply to Re: How do I reverse the order of the first and last word of a string?
by jonadab
in thread How do I reverse the order of the first and last word of a string?
by ferrispike12
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |