in reply to splitting
Assuming your delimiters are
' ',',', or ';',for example, doing
gives us:perl -e'print join "!!",split /([ ,;])/,"This sentence contains, in he +re, a comma; and there's a semicolon clause\n";'
This!! !!sentence!! !!contains!!,!!!! !!in!! !!here!!,!!!! !!a!! !!comma!!;!!!! !!and!! !!there's!! !!a!! !!semicolon!! !!clauseThis trick uses the fact that
join "{some delimiter string}",@arrayreturns the contents of @array, separated by the delimiter string.
As you can see, things like ", " confuse it, so you might want to use a + inside the parentheses if you can afford to collect multiple separators into one array slot.
That's a bit better; now we get:perl -e'print join "!!",split /([ ,;]+)/,"This sentence contains, in h +ere, a comma; and there's a semicolon clause\n";'
This!! !!sentence!! !!contains!!, !!in!! !!here!!, !!a!! !!comma!!; !!and!! !!there's!! !!a!! !!semicolon!! !!clauseHope this helps...
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Re: splitting
by chromatic (Archbishop) on Apr 28, 2000 at 01:25 UTC | |
by perlmonkey (Hermit) on Apr 28, 2000 at 01:49 UTC |