in reply to Validating Regular Expression
where it returns the compiled regular expression if it succeeds (TRUE) or undef if it fails (FALSE). (use strict; use warnings; for ('a*', '*') { print validate($_) ? "Pass: '$_'\n" : "Fail: '$_'\n"; } sub validate{ my $pat = shift; return eval{qr/$pat/}; }
Blah blah, security, blah blah, trusted source, blah blah, injection attack, blah blah, perlsec.
Update: In deference to ikegami's comment, I have revised the above; however I would point out that Perl Best Practices agrees with me (point 124 - Use a bare return to return failure). I think we can both agree that the interface you specify should depend on how you are going to use it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Validating Regular Expression
by ikegami (Patriarch) on Feb 15, 2011 at 17:06 UTC | |
|
Re^2: Validating Regular Expression
by ikegami (Patriarch) on Feb 15, 2011 at 17:35 UTC | |
by kennethk (Abbot) on Feb 15, 2011 at 17:53 UTC | |
by ikegami (Patriarch) on Feb 15, 2011 at 18:15 UTC |