That is no a split then, that is a pattern match. The problem remains that a line like 'a::b:: c' will match according to your rules but the result will be 'a', ':b', 'c'. You can do this easily with recursion:

my @split_bits = qw( : :: \s+ ); my @result = wierd_split( 'foo:bar::baz boo:foo::bar::baz', \@split_b +its ); print "Got $_\n" for @result; sub wierd_split { my ( $str, $to_do, $got ) = @_; return (@$got, $str) unless @$to_do; my $next_split = shift @$to_do; print scalar @$to_do, " splitting '$str' on '$next_split'", "\n"; my ( $want, $next ) = $str =~ m/(.*?)$next_split(.*)/m; print "'$want' '$next'\n"; push @{$got}, $want; # and now for a little recursion wierd_split( $next, $to_do, $got ) if $want; } __DATA__ 2 splitting 'foo:bar::baz boo:foo::bar::baz' on ':' 'foo' 'bar::baz boo:foo::bar::baz' 1 splitting 'bar::baz boo:foo::bar::baz' on '::' 'bar' 'baz boo:foo::bar::baz' 0 splitting 'baz boo:foo::bar::baz' on '\s+' 'baz' 'boo:foo::bar::baz' Got foo Got bar Got baz Got boo:foo::bar::baz

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: Re: Re: Re: expanding the functionality of split by tachyon
in thread expanding the functionality of split by tigervamp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.