in reply to Is it possible to store an arthimetric operator in a variable?

As transient said, eval offers the most straightforward answer to what was asked; so to put this into your code:
if ( eval ( "$num $eq $1") ) {

One world, one people

  • Comment on Re: Is it possible to store an arthimetric operator in a variable?
  • Download Code

Replies are listed 'Best First'.
Re^2: Is it possible to store an arthimetric operator in a variable?
by radiantmatrix (Parson) on Jul 19, 2005 at 16:37 UTC

    It is worth mentioning that one shouldn't eval user-supplied strings until they have been checked for safety (untainted). If a user is supplying the value for $eq, they could supply Perl code that would be executed: obviously, that's potentially dangerous.

    <-radiant.matrix->
    Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
    The Code that can be seen is not the true Code