|Don't ask to ask, just ask|
Re: Idiomatic Perl? -- eval qr/ /by Discipulus (Abbot)
|on Mar 20, 2018 at 20:37 UTC||Need Help??|
Hello thenextfrater and welcome to the monastery and to the wonderful world of Perl!
haukex and choroba are both wise and right about possibly dangerous uses of eval but since you are asking the user to enter a regex you must be sure that is a valid one; infact your code allows to pass a wrong regex:
So sometimes eval is useful and imho one these cases is compiling a regex (see qr// in perl documentation):
So do not avoid eval because it can be dangerous: know it and profit it! Obviously you do not use a bazooka to kill a mosquito.. do you?
PS about arbitrary code execution I was tempted to add also regex can lead to code execution but perl is wise in this: not arbitrary code:
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.