Tackling this problem via eval is possible with Perl, but it surely is not wise to attack this problem with this tool.

I guess you want something like the following, a hand-coded and much gentler version of eval, that only evaluates the intended stuff (untested):

use strict; my %variable; my %operation; $operation{eq} = sub { my ($op1, $op2) = @_; return $op1 eq $op2; }; $operation{ne} = sub { my ($op1, $op2) = @_; return $op1 ne $op2; }; sub evaluate { my ($var,$op,$value) = @_; if (defined $operation{$op}) { my $code = $operation{$op}; return $code->( $variable{$var}, $value ); } else { die "Unknown operator : $op\n"; }; }; $variable{foo} = 'FOO'; $variable{bar} = 'BAR'; my ($var,$op,$val); foreach $var (keys %variable) { foreach $op (keys %operation) { foreach $val ('FOO','BAR','neither') { print "$var $op $val :", evaluate( $var, $op, $val ), "\n"; }; }; };

More operators are added easily - you could now turn again to Perl to write these operators for you, but it is better to approach the problem slowly instead of drinking the whole sea at once :-)

Of course the above assumes that all your status variables are collected together in a separate hash, as it's a generally bad idea to use symbolic references (see Dominus' homepage for a discussion). If you really really really think you must get at the variable names from within your program, ask that in a separate question.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

In reply to Re: Configurable comparisons by Corion
in thread Configurable comparisons by asiufy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.