in reply to Using dynamic operators in an if() statement

I think you're trying to remember,

my $operator = '> 98.0'; if ( eval $consumption . $operator ) { }
I think that absorbing the operator into a string to be eval'd doesn't get you anything you want. I'd prefer,
sub LIMIT () { 98.0 } if ($consumption > LIMIT) { }

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Using dynamic operators in an if() statement
by ikegami (Pope) on Aug 22, 2006 at 05:31 UTC

    Shouldn't that be

    if ( eval "\$consumption $operator" )

    I doubt the existance of a need to stringify and evaluate the contents of $consumption.