in reply to Re: howto parse (or determining end) of a line of perl
in thread howto parse (or determining end) of a line of perl

eval "sub DUMMY { $code }; 1" ..." -- that does something if "$code" contains a sub, but if you are willing to allow for "less than perfect" (fine for most personal toys), then yeah... don't really need the sub on the outside as it doesn't really provide any extra protection that I know of.

Another layer of "less than perfect" protection, but w/the advantage of getting a 'default' (overridable) namespace protection, is to put the evaluated code in a separate package namespace -- so all my calculator's namespace evals are done in a 'USER' namespace -- so user routines and constants default to be separated from my machinery namespace (the keyword in many of these solutions being 'default' to allow for simple, DWIM behavior).

I think there might be some better sandboxing mods in CPAN, if you wanted to get paranoid, but might not be worth the overhead/side effects for a personal 'toy'....;-)

Replies are listed 'Best First'.
Re^3: howto parse (or determining end) of a line of perl
by RonW (Parson) on Aug 26, 2016 at 19:19 UTC
    don't really need the sub on the outside as it doesn't really provide any extra protection that I know of

    It prevents the code from being executed. Except, of course, for BEGIN blocks and use statements (which also execute when you use the -c (compile only) option to perl).