Is my eval wrong or do I not understand eq vs == in Perl -
i having trouble understand eval or maybe not understand eq vs ==. have short perl script:
[red@tools-dev1 ~]$ cat so.pl #!/usr/local/bin/perl -w use strict;  while(<data>) {     chomp;     ($arg1, $arg2, $op ) = split /,/;     if ( $op eq '=' ) {         $op = 'eq';     }     $cmd = "$arg1 $op $arg2";     print "[$cmd]\n";     $rc = eval $cmd || 0;     print "rc [$rc]\n"; }  __data__ cat,cat,=   when execute get:
[red@tools-dev1 ~]$ ./so.pl [cat eq cat] rc [0]   one think you'd ...
[cat eq cat] rc [1]   ... since "cat" equals "cat", right?
you're using barewords in strict mode, error:
$ perl -e 'use strict; cat eq cat' bareword "cat" not allowed while "strict subs" in use @ -e line 1. bareword "cat" not allowed while "strict subs" in use @ -e line 1. execution of -e aborted due compilation errors.   whenever eval string, should check $@ see if there error.
Comments
Post a Comment