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

When you tie and untie a variable what happens to the old contents of the variable?

Is it thrown out the nearest airlock or restored upon untieing?

Details: I'm using Apache::Session to tie a global %sessions hash under mod_perl & HTML::Mason. As this global persists across multiple apache child process requests (and different sessions), I don't want an accidental coding mistake to pass sensitive information from one session into a different one. I figure the best strategy is to tie %sessions in the root autohandler's <%init> section and then untie it in the root autohandler's %cleanup section.

Am I doing this the right way?

-Andrew.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

Replies are listed 'Best First'.
Re: tie and untie old value
by Arunbear (Prior) on Aug 06, 2005 at 21:01 UTC
    This issue is discussed in the Mason book.

    In short localize %sessions with

    local *sessions;
    in the root autohandler. Then %sessions automagically gets untied when it goes out of scope.

Re: tie and untie old value
by ysth (Canon) on Aug 07, 2005 at 05:00 UTC
    After untie, you should not count on a variable's pre-tie content being still there.

    In practice, this mostly works for arrays and hashes, and mostly not for scalars.