in reply to interpolating a variable into an operator
I am trying to store operators in a variable and then use the variable as the operator
Lisp can do this; Perl cannot. It can, however, store an anonymous *subroutine* in a variable. This is syntactically different from an operator, but it can accomplish the same effect:
$op = sub { $_[0] eq $_[1] }; if($op->($somvar, "some text")){ #do stuff }
Resist the urge to use string eval for this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: interpolating a variable into an operator
by diotalevi (Canon) on Jul 20, 2004 at 19:16 UTC | |
by ihb (Deacon) on Jul 20, 2004 at 20:31 UTC | |
by diotalevi (Canon) on Jul 20, 2004 at 20:44 UTC |