in reply to help: 'Complex' split

When it's easier to talk about what you want to keep than what you want to throw away, then it's time to use m//g instead of split. I'd start with something like:
my @pieces = m/\G(<[^>]*>|#[^#]*#|[^#<]+)/g;
No error checking here. If you wanted error checking, inch along until pos() is at the end of the string, or take the error if it's not and there's no match. Something like:
pos = 0; while (m/\G(<[^>]*>|#[^#]*#|[^#<]+)/gc) { push @pieces, $1; } die unless pos >= length;
It would be nice if list-context m//gc left pos at the last match, but last I checked it was still broken.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: help: 'Complex' split
by vladb (Vicar) on Dec 26, 2001 at 22:07 UTC
    Excellent!! it works for me.. ;-). thank you so very much.

    you notice vladb departing to his cubicle overjoyed...

    "There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith