in reply to Re: Possible to use "split", but save the delimiter?
in thread Possible to use "split", but save the delimiter?

Hi,

This almost works:

my $test = qq|1-10,20 some.thing [[else]],bla bla bla|; my @temp = split /([,-\s\.\]\[]+)/, $test; use Data::Dumper; print Dumper(@temp);


..but for some reason, it doesn't seem to like the ]] bit :

1 - 10 , 20 some . thing [[ else ]], bla bla bla


We need it to split at:

[[ ]] , - \s .


Any suggestions?

TIA!

Andy

Replies are listed 'Best First'.
Re^3: Possible to use "split", but save the delimiter?
by BrowserUk (Patriarch) on Feb 10, 2010 at 17:02 UTC

    This what you're after?

    $s = qq|1-10,20 some.thing [[else]],bla bla bla|;; print "'$_'" for split /([-, .]|\[\[|\]\])/, $s;; '1' '-' '10' ',' '20' ' ' 'some' '.' 'thing' ' ' '' '[[' 'else' ']]' '' ',' 'bla' ' ' 'bla' ' ' 'bla'

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks - works a charm <G>