in reply to To use do or eval

I would say that string eval would be the way to go (not the least because do isn't orthorganal with eval :) e.g
my $code = $dbh->selectrow_array($sql) or warn "no code - ", $dbh->errstr; do { eval($code); $@ } or warn "broken code - $@";
So that will run the code from the database and warn if there are any errors when it's run.
HTH

_________
broquaint

update: as sauoq rightly points out below, my code was b0rken (I was under the impression eval returned the value of $@, how silly of me) it's now been fixed with a do block hack

Replies are listed 'Best First'.
Re: Re: To use do or eval
by sauoq (Abbot) on Jun 03, 2003 at 18:46 UTC
    eval($code) or warn "broken code - $@";

    That's a big oops.

    The problem is that eval() returns whatever the eval'd code does. That would fail if the last expression in the code resulted in any false value, even if the code was perfectly fine. The Right Way™ is to check whether $@ is true.

    my $result = eval($code); warn "eval borked: $@" if $@;

    -sauoq
    "My two cents aren't worth a dime.";