in reply to newline behavior in Regular Expression

I may be out of line with this but why are you using eval when it seems to me that you could have done this without it?

Something along the lines of:

if($X ~= s{^(.*?)Resolved (\d+) problems out of (\d+) picked(.*?) +$}) { return ($3-$2/$3>.5) ? 1 :0); }

Of course, I could be completely off the mark.

Replies are listed 'Best First'.
Re: Re: newline behavior in Regular Expression
by qq (Hermit) on Apr 12, 2004 at 21:15 UTC

    I agree, eval seems unneeded here. You can still use s///, although I would prefer it like yours.

    #!/usr/bin/perl my $x = "Line1\nLine2Resolved 200 problems out of 5000 picked\nLine4\n +Line5"; $x =~ s/.*?Resolved (\d+) problems out of (\d+) picked.*/ ($2 - ($1\/$2)) > .5 ? 1 : 0 /es; print "$x\n";

    Remember to escape the division in the substitution.

    qq