I'm having trouble understanding eval, or maybe I do not understand eqvs ==. I have this short Perl script:
[red@tools-dev1 ~]$ cat so.pl
use strict;
while(<DATA>) {
chomp;
my ($arg1, $arg2, $op ) = split /,/;
if ( $op eq '=' ) {
$op = 'eq';
}
my $cmd = "$arg1 $op $arg2";
print "[$cmd]\n";
my $rc = eval $cmd || 0;
print "rc is [$rc]\n";
}
__DATA__
cat,cat,=
When I execute it, I get:
[red@tools-dev1 ~]$ ./so.pl
[cat eq cat]
rc is [0]
You might think that you get ...
[cat eq cat]
rc is [1]
... since "cat" is equal to "cat", right?
source
share