in reply to Complex Splitting

You're better of using a matching regex rather than a split:

@arr = $str =~ /(\w|\[\w+\])/g;

Update: thanks to monarch for pointing this out. The above leaves the brackets behind. One option is to split the capture and filter out the undefs thus:

@arr = grep $_, $str =~ /(\w)|\[(\w+)\]/g;

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Replies are listed 'Best First'.
Re^2: Complex Splitting
by eric256 (Parson) on Feb 06, 2007 at 14:01 UTC

     @arr = grep {defined} $str =~ /(\w)|\[(\w+)\]/g; gets exactly what you wanted without the brackets. Not sure how to avoid the undef's except grepping them out.


    ___________
    Eric Hodges