in reply to Splitting on unusual regex

Within the constraints you've outlined, seems like this might work for you?

print for $s =~ m[( (?: \( [^)]+ \) ) | \S+ )]gx;; this is (some more) JOY code

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Splitting on unusual regex
by dewey (Pilgrim) on May 14, 2007 at 04:24 UTC
    Yeah, you're right that I should abandon split and this nearly works-- the one thing (which may have been unclear above) is that I'd like it to ignore escaped parentheses, so that
    ( some stuff\) )
    is not split up. I'm working on a variation that ignores \) and \( and will fit into my code like this:
    for ($script =~ m[( (?: \( [^)] + \) ) | \S+)]gx) { push @script, $_; }

    ~dewey

      Something like this?

      #! perl -slw use strict; my $code = <<EOC; This is some JOY code This is (some more) JOY code And this is some JOY code with escaped \\( and \\) like (this \\) and \\(this) and \\) EOC print for $code =~ m[ ( (?: \( (?: \\[()] | [^()] )+ \) ) | \S+ ) ]gx; __END__ C:\test>615217 This is some JOY code This is (some more) JOY code And this is some JOY code with escaped \( and \) like (this \) and \(this) and \)

      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.
        Exactly... man, I'm really going to have to resist the urge to put all my questions on here or I'll never write any of my code myself! Thanks a lot guys, I'm slowly improving at regular expressions.

        ~dewey