jdgamache has asked for the wisdom of the Perl Monks concerning the following question:

Here is my problem, I want to build a perl code library. I need to validate the perl code entered. here is what i do:
# check to see if code is valid sub check_valid_code { my ($lang, $code) = @_; if ($lang eq 'perl') { $code .= "\n1;\n"; return eval ($code); } 0; }
well.... this validates the code all right! the problem is that it executes the perl code also ;) I need another way to check if the code is valid... but does not execute it. any ideas ?!? thanks! Jean-Daniel

Replies are listed 'Best First'.
Re: Check if perl code is valid
by merlyn (Sage) on Jan 15, 2001 at 00:00 UTC
      I may be missing something here, but couldn't you check the return value of a system('perl -c...')?

      (and before this gets --'d too much, explain why it's a bad idea..)

      -marius
Re: Check if perl code is valid
by I0 (Priest) on Jan 15, 2001 at 00:07 UTC