[boulder.pm] Persistant Data

Rob Nagler nagler at bivio.com
Mon Jul 17 22:46:48 CDT 2000


>     If I take out the "BEGIN" and "END" and just have those code blocks in the
> main body of the script, it works perfectly, but it doesn't seem to work with
> that code in those special blocks.  

I would guess that it would work with it in the END block, but not the
BEGIN block.  BEGIN executes "first", before the rest of the code.

my($v) = 2;

BEGIN {
    $v = 1;
}

print $v;

This will print "2", not "1" as you would think.   

We rarely use BEGIN blocks.  Usually, only when we need to do something 
that is particularly tricky and then only in modules, not programs.

I'm sure there's even stranger stuff with tying variables.   We stay
as far away from those as possible. :-)

Why not simply use a hash_ref that is always tied for the values instead
of the intermediate variables?  Moreover, why not make a little wrapper
object that managed the whole thing?



More information about the Boulder-pm mailing list