in reply to Dynamic operators

please do NOT use $a and $b since this variables are reserved for use with sort. you can use the eval call:
use strict; my $n1= 10; my $n2= 20; my $operator= "=="; my $expr = "$n1 $operator $n2"; my $erg = eval $expr; die if ($@); if ($erg) { print "true\n"; } else { print "false\n"; }

Replies are listed 'Best First'.
Re: Re: Dynamic operators
by demerphq (Chancellor) on Sep 11, 2002 at 11:41 UTC
    While you have a valid point, the variables are not "reserved", they are simply used. Avoiding them is a good way to avoid really hard to track down errors, but if sort() is not used then they are fine.

    --- demerphq
    my friends call me, usually because I'm late....

      they are not just simply used since strict.pm for example does not "check" them. another point is that any programmer shots himself/herself in the foot when using such imaginable variable names - except sort of course. variable names with a length less than, say, 4 should generally be disallowed. but that is only my opinion. ;)