On 5 Jun 2002 at 17:18, Morse, Richard E. wrote:
> Charles Oppenheimer [mailto:[EMAIL PROTECTED]] wrote:
>
> > Hi folks. I have a question... I wanted to create a
> > sub procedure that takes an operator as an argument,
> > like so:
> I've never actually done this, so I'm somewhat guessing here, but you
> might be looking for something like:
>
> sub compare {
> my ($a, $o, $b) = @_;
> if (eval("$a $o $b")) {
> print "True!\n";
> }
> }
>
you also might want to try this, if speed is an issue, it is
significantly faster:
sub get_template_compare
{
my ($operator) = @_;
return eval qq
{
sub { \$_[0] $operator \$_[1] }
}
||
die "Template Code compilation failed\n";
}
*template_compare = get_template_compare('<');
# check logic:
die unless template_compare(1,2);
die if template_compare(3,2);
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs