in reply to expanding the functionality of split
Are there easy ways to acheive the general ideas here without modifying split?
Sure is. Just use the old join with '|' trick which is very useful for matching an array of patterns. You may or may not want to do a map { quotmeta } @paterns. The sort on length is so that we match '::' before ':'
$string = "a:b::c d"; @patterns = (':','::','\s+'); my $re = join '|', sort { length $b <=> length $a } @patterns; @fields = split /$re/, $string; print "Got '$_'\n" for @fields; __DATA__ Got 'a' Got 'b' Got 'c' Got 'd'
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|