in reply to Persistent Variable

I think you're headed in the right direction. Typically the best way to implement something like this is to pass around a single variable reference (either an object or a hash reference are common) with all of your state information.
my $state = { username => $username, sessionid => $sessionid, whatever => $else, }; &one($state, $other_args); &two($state, @more); &three($state);
Another way of doing this is to turn $state into an object, and turn one, two and three into object methods.
$state = new Object($username, $sessionid); $state->one($other_args); $state->two(@more); $state->three;
I kind of like things like Class::Struct for defining a simple object-ish representation of a data structure like that, which is easy to pass around as a single unit.

Replies are listed 'Best First'.
Re: Re: Persistent Variable
by Anonymous Monk on Jan 15, 2001 at 22:35 UTC
    Okay, I was thinking of creating a package "Common" that would hold the state variables. Can you "set" a variable in a package and be able to retrive it later if you maintain the pointer to the package? For instance..
    package Common; my $session; #main program $comm=new Common; $comm->session="1234"; $temp=$comm->session; print "$temp";
    would this print out 1234 or can you not assign variables inside packages like this? Thanks.
      $Common::variable = "value"; print $Common::variable; # 'value'