in reply to expanding the functionality of split
Update: fixed - needed nested brackets to abort looking for another field after a delimiter has failed to match.#!/usr/bin/perl -wl use strict; sub msplit { my ($delim, $str) = @_; my $pat = ''; $pat = "(?>(.*?)$_$pat)?" for reverse @$delim; grep defined, $str =~ /^$pat(.+)/; } print for map "'$_'", msplit [qw(: :: \s+)], "a:b::c d"; __END__ 'a' 'b' 'c' 'd'
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: expanding the functionality of split
by BrowserUk (Patriarch) on Dec 10, 2002 at 19:03 UTC | |
by Aristotle (Chancellor) on Dec 11, 2002 at 09:48 UTC | |
by BrowserUk (Patriarch) on Dec 11, 2002 at 14:42 UTC | |
by Aristotle (Chancellor) on Dec 11, 2002 at 15:06 UTC | |
by BrowserUk (Patriarch) on Dec 11, 2002 at 15:17 UTC |