Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: newline behavior in Regular Expression

by cyocum (Curate)
on Apr 12, 2004 at 21:00 UTC ( #344522=note: print w/replies, xml ) Need Help??

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.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://344522]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-10-24 10:15 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.