Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Perl

Idiom #283 Split with a custom string separator

Build the list parts consisting of substrings of input string s, separated by the string sep.

@parts = split quotemeta($sep), $s;

The first argument to split is actually a regular expression. Wrapping the separator character with quotemeta ensures it will treat pattern metacharacters as plain old characters.

Variable names starting with @ signify a list; those with a $ are scalars.

You must assign to a list variable to get a list returned.
(def parts (clojure.string/split s sep))

ensure sep is a Regex

New implementation...