Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: ?Re: Re: Re: How to identify invalid reg. expr.?

by mephit (Scribe)
on Jun 05, 2002 at 20:50 UTC ( [id://172005]=note: print w/replies, xml ) Need Help??


in reply to •Re: Re: Re: How to identify invalid reg. expr.?
in thread How to identify invalid reg. expr.?

Here we go: Just to verify, I just changed it to
eval { use re 'eval'; no warnings; "" =~ /$searchstring/ };
Run from the browser, it generates an internal server error (the log complains of premature end of script headers, regardless of how the script is run.) but no coredump. When run from the command line, the script is aborted and does dump core. Umm, yay. (Maybe the lack of core dump is due to apache? I'll look into it.)

So, I'll consider removing the regex search completely, or building one from pieces as samtregar mentioned in a previous post. (I already have AND and ANY searches, though. We'll see what I can come up with.) Thanks for the tips, folks.

--

There are 10 kinds of people -- those that understand binary, and those that don't.

Replies are listed 'Best First'.
•Re: Re: ?Re: Re: Re: How to identify invalid reg. expr.?
by merlyn (Sage) on Jun 05, 2002 at 20:59 UTC
    No, that's backwards. If you're building CGI, you do not want to use re eval. The default is the safety that I insisted they add.

    Just use this:

    my $regex = param('foo'); $regex = eval { qr/$regex/ }; if ($@) { "it was bad... handle it" }
    Then use $regex later, safely, as a compiled regex. In fact, wait, it's simpler than that:
    my $regex = param('foo'); $regex = eval { qr/$regex/ } or do { # handle failure };
    since eval will return undef on a failed block, or the compiled Regex object (always true) if it's a valid regex.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found