Eval Errors

From: James Edward Gray II (james_at_grayproductions.net)
Date: 02/23/04


To: Perl Beginners <beginners@perl.org>
Date: Mon, 23 Feb 2004 10:35:28 -0600

I'm having a heck of a time getting eval() to obey me this morning and
I thought I would see if I can get a fresh perspective from someone.

Okay, I'm passing a server I wrote some Perl code I want it to eval().
This morning, during testing, I fed it some bad code. It's supposed to
handle that by doing nothing and giving me the error that was
generated, so I can fix it and try again. It is doing these things,
but it's generating some warnings on the server, I want to silence.
Here's what the relevant code looks like:

        my %details = eval $replacements{ACTION_DETAILS};
        if ($@) {
                # tell me what went wrong... (working)
        }

($replacements{ACTION_DETAILS} is supposed to eval() to a hash
initializing list, naturally.)

When I run this, feeding it the error containing code, the server spews
the following warnings:

Odd number of elements in hash assignment at libs/Improv/Director.pm
line 29.
Use of uninitialized value in list assignment at
libs/Improv/Director.pm line 29.

(libs/Improv/Director.pm is the module that contains the code shown
above and line 29 is the eval() line of the above snippet.)

That much makes sense to me. eval() is returning undef since the code
didn't compile and that's tripping both of the above warnings. Got it.

So I tried a simple fix:

        my %details = eval($replacements{ACTION_DETAILS}) || ();

And to my surprise, that made things much worse. The server now
complains:

Bareword found where operator expected at (eval 9) line 1, near "'sub {
my $self = shift; my $actor = shift; $actor->sense("The rose has the
crisp smell of shaved ice.\n"); if ($self->{Owner}->isa('Improv::Set"
         (Missing operator before Improv::Set?)
String found where operator expected at (eval 9) line 1, near
"Improv::Set')) { $_->sense("$actor->{Name} leans over $self->{Name}
and inhales.\n") foreach $self->{Owner}->get_actors($actor); return 1;
}'"

That slew of errors is complaining about the code I passed eval().
Those are the errors I made in the code I handed the server. I can fix
the error, that's not the issue. I don't understand why the server is
complaining about what happened inside an eval().

So I tried some other fixes:

        my %details;
        {
                no warnings;
                %details = eval $replacements{ACTION_DETAILS};
        }

And:

        my %details;
        eval "%details = $replacements{ACTION_DETAILS}";

Both of these give me the second set of errors I posted above, the
errors that keep the code in $replacements{ACTION_DETAILS} from
compiling. That confused me even more. How the heck is shutting off
warnings increasing the complaints?

I believe I have a solution now. I'm going to try switching the way
the system works to eval() to a hash reference, instead of a hash. I
expect that to silence the two original warnings caused by the undef
being returned.

However, I don't understand why the server was complaining about the
the code inside the eval() with all of my attempted fixes. My
understanding was that eval() should trap the errors and I'll find them
in $@. If anyone can enlighten me as to what the heck is going one
here, I would be most grateful.

Thanks.

James



Relevant Pages

  • Re: Event Warning 40961 LSASRV
    ... Also, the netlogon service is not running on either server, yet I'm still ... getting warnings about authentication failure to the providers nameserver. ... Also, after making the registry entry previously stated, DNS services were ...
    (microsoft.public.windows.server.networking)
  • Re: False Alert - AD database restored by unsupported procedure.
    ... DNS entries for this DC cannot be verified right now on DNS server ... the DNS and SPN warnings. ... Run dcdiag, netdiag and repadmin in verbose mode. ... And I alway restart the net logon service when I ...
    (microsoft.public.windows.server.active_directory)
  • Re: False Alert - AD database restored by unsupported procedure.
    ... the DNS and SPN warnings. ... If you don't have the support tools installed, install them from your server ... Run dcdiag, netdiag and repadmin in verbose mode. ... And I alway restart the net logon service when I ...
    (microsoft.public.windows.server.active_directory)
  • Re: Lost data on socket - Can we start over politely?
    ... I also implemented strict and warnings. ... > buffering issue. ... > I've switched to using only buffered reads and writes on the socket fd's, ... Instead please try this server (some quickly reduced code from a bigger ...
    (comp.lang.perl.misc)
  • Re: SBS2003 New instralaltion onto a Dell POweredge 2900
    ... I installed the 948496 patch first, reset the server and the remote desktop ... Server administrator, and navigate to `virtual disk`, there set cache to ... this has been one of the worst installs I have ever had in a long time. ... and I have to say I'm frustrated in what the heck is ...
    (microsoft.public.windows.server.sbs)