No sweat in Perl:
#! /usr/bin/perl
local $_ = "Hattie:07903 000066::Dad:07854 000095::Tom:07903 000044::Allistair:07765 000005::Home:0115 974 0000::";
print "<ol>\n",
map("<li>$_</li>\n", split /::/),
"</ol>\n";
As used in your question, the sequence ::
is a terminator and not a separator, which makes split
a bit of a conceptual mismatch. To fit the format more closely, use a regular-expression match in list context with /g
The /g
modifier specifies global pattern matching—that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression.
and a non-greedy quantifier
By default, a quantified subpattern is “greedy,” that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a ?
. Note that the meanings don't change, just the “greediness” …
That amounts to
print "<ol>\n",
map("<li>$_</li>\n", /(.+?)::/g),
"</ol>\n";
Either way, the output is
<ol>
<li>Hattie:07903 000066</li>
<li>Dad:07854 000095</li>
<li>Tom:07903 000044</li>
<li>Allistair:07765 000005</li>
<li>Home:0115 974 0000</li>
</ol>