more useful options | |
PerlMonks |
Re: '+' to +by monarch (Priest) |
on May 29, 2005 at 12:16 UTC ( [id://461501]=note: print w/replies, xml ) | Need Help?? |
I'm sure there are better ways than the one I'm about to suggest. Firstly you've used a regexp to clean up the input, very good, you're protecting yourself against potentially nasty input from the source.. because real-world programmers know real-world people try and stick anything into our machines! Perhaps you could make the regexp ensure the operator is only one of the four specified operations and then performing an eval on the reconstructed operation? e.g.
Of course if statements should be littered about to ensure the regexp actually matches etc. Update: as wfsp pointed out below I have now escaped the forward slash in the regexp because the forward slash is the regexp delimiter.
In Section
Seekers of Perl Wisdom
|
|