Re: Eval Errors

From: James Edward Gray II (
Date: 02/23/04

Date: Mon, 23 Feb 2004 14:21:51 -0600
To: Perl Beginners <>

As several have pointed out now, my description of the problem was
involved. Sorry about that. I was showing you a tiny slice of the
3,000 line server where I know the problem is occurring.

However, thanks to the help provided, I managed to simplify the problem
to a small script. We can talk about this sucker and all be on the
same page. Behold:


use strict;
use warnings;

my @strings = ( q(my $bad_syntax = ;),
                                q('a poorly 'nested' string'),
                                q('a poorly 'nested::test' string') );

foreach (@strings) {
        print "\nCode: $_\n";
                print "\nDisabling warnings...\n";
                no warnings;
                print "Calling eval()...\n";
        print "eval() complete.\n\n";
        if ($@) {
                print "Handling error...\n";
                print "Caught error: $@";


Interesting things to note about the above: All three @strings are bad
perl code and don't compile. Warnings are disabled when I run the
eval() and thus, not a part of the equation. (The script runs
identically if they are left on.) We're not catching eval()'s return
value here, so it's not part of the equation either. Note how similar
the second and third string are as well.

When I run this code, I get:

Code: my $bad_syntax = ;

Disabling warnings...
Calling eval()...
eval() complete.

Handling error...
Caught error: syntax error at (eval 1) line 1, at EOF

Code: 'a poorly 'nested' string'

Disabling warnings...
Calling eval()...
eval() complete.

Handling error...
Caught error: Bad name after nested' at (eval 2) line 1.

Code: 'a poorly 'nested::test' string'

Disabling warnings...
Calling eval()...
Bareword found where operator expected at (eval 3) line 1, near "'a
poorly 'nested::test"
         (Missing operator before nested::test?)
String found where operator expected at (eval 3) line 1, near
"nested::test' string'"
eval() complete.

Handling error...
Caught error: syntax error at (eval 3) line 1, near "'a poorly


The first two results are what I expect/want. The third string, a
super simplified example of the typo I fed my server this morning,
throws errors inside the eval() call and yet the script keeps on
trucking along!

Can anyone explain to me what's going on here?


Relevant Pages

  • Re: Sencha Touch--Support 2 browsers in just 228K!
    ... this particular script is so awful that anyone who could ... These functions are available on every String object. ... if (!dom) { ... @param o The object with the attributes ...
  • Re: How to rewrite with awk?
    ... > I'm unfamiliar with tools such as sed & awk. ... Extract the string that matches a RE. ... This script will not only expand all the lines that say "include ... file) and not resetting ARGV(the tmp file), it then lets awk do any ...
  • Re: Slow string
    ... I see virtually no difference in execution time for the code you posted when using cscript versus using wscript; to confirm, I bracketed the code with an initial ... Are you actually entering the script name into a console window? ... You can use the exact same line for every wrapper script - and that includes wsf and js scripts; all you need to do is change the final "vbs" to "wsf" or "js" as appropriate. ... If you build a large string by small concatenations, the performance degrades geometrically - so does array resizing, because they both use the same nasty technique inherited from VB1 of copying the entire data structure to a new structure with the added element. ...
  • Re: Function that returns date of file.
    ... string after the date/time when it is used by itself. ... Is that your entire script? ... I make an IF statement that required the 'equals equals'. ... designed database your job will be all that much harder. ...
  • Multiple vulnerabilities found in CSGuestbook by
    ... About this script: This is an open source GuestBook script offered by ... About the audit: This audit was performed by Daxgrapol and Dopel for RACAT. ... Only the first special character is filtered off of the return string. ... - Buffer overflow is possible (input field length not checked). ...