Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
my $covCounter = 0; open(EVALUATION, "< $evalFile[0]") or die $!; undef $/; (my $shortFile = <EVALUATION>) =~ s/^.+-+ END -+//gs; $shortFile =~ /(?(^(\d+ )+\s+(\d+)+$)(?{$covCounter++}))/gm; close EVALUATION;
I get always the message "unknown switch condition m/(?(<--HERE". Why unknown? Where is my fault? Thats supposed to be a if then Regex with an integrated Perl counter. What do I wrong? Thank you very much for your help.

20050329 Edit by ysth: code tags

Replies are listed 'Best First'.
Re: Regex (?(...)...)
by ikegami (Patriarch) on Mar 29, 2005 at 21:42 UTC

    You appear to be using the (experimental) construct (?(...)...) incorrectly. In fact, I don't know why you're using it at all.

    $shortFile =~ /^(\d+ )+\s+(\d+)+$(?{$covCounter++})/gm;

    And you're also using the experimental construct (?{...}) for no good reason.

    $shortFile =~ /^(\d+ )+\s+(\d+)+$(?{$covCounter++})/gm;
    can be written as:
    $covCounter++ while $shortFile =~ /^(\d+ )+\s+(\d+)+$/gm;

    btw, please use <code> tags around your code.

      Thank you very much and sorry for the ugly post. Your right. Keep things simple.
Re: Regex (?(...)...)
by Joost (Canon) on Mar 29, 2005 at 21:38 UTC