If the delimiter is a constant then simply doing a join should work to reverse it.
my $delim = ':TAG:'; my @data = split $delim, $line; my $line = join $delim, @data;
If the delimiter varies, ie. is a regexp, then things get more fun, but I'll only think about that if needed.
The other obvious solution is to keep a copy of the original line about, no point rejoining if it's practical to simply throw it back out.
Update: Misunderstood the question somewhat. If you're happy with keeping the tag at the start then a lookahead regexp assertion may be just what you're looking for. Have a look at this.my $data = ":TAG:This:TAG:is:TAG:a:TAG:test:TAG:"; my @results = split /(?=:TAG:)/, $data;
I've not played with these things properly so I have no idea how performant they may be, however.
In reply to Re: Splitting and maintaining the delimiter
by Molt
in thread Splitting and maintaining the delimiter
by Rich36
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |