Conrad, Bill (ThomasTech) <> wrote:
> Hi All
>
> If I have some Perl code in a variable $code and I use and
> eval($code) to execute the code can I do something like
>
> sub x {
> my ( $code
> , $other_stuff
> ) @_ ;
>
> my %save_sym = %main:: ;
>
> eval($code) ;
>
> %main:: = %save_sym ;
>
> }
>
> to remove any symbols created within the code from the symbol table?
> Is this a good practice or is there a better way?
Apart from the times when it is unavoidable, block evals are preferable
to string evals. Unless you have complete control over the string being
eval-ed it can represent a rather large security hole.
Regarding saving the symbol table. It is not just the removal of symbols
created, but modification of existing symbols that may need taking care
of. Also, copying a hash just copies keys and values. If the any values
are references, only the reference is copied, not what it refers to, so
the reverse copy will not restore the state of that object after the
eval. Don't forget that lexical variables don't appear in the symbol
table, so you symbol table copy will not restore any changes made to in
scope variables made in the eval.
There a re probably lots of other problems too.
Sounds pretty dodgy to me. Perhaps if you said what you were trying to
accomplish by this it might be easier for someone to suggest a better
way.
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs