in reply to Persistent Variable

First off, if you are already comfortable with OO thinking, then you might want to check out Perl's OO. Its not as solid as Java or C++, but it is there. (perltoot is a good tutorial.)

Ok, on to your question:
You don't need a separate package for these variables. If you declare the variables in your script before declaring any subs then all the subs in main:: can see them. If you have them in a namespace other then main::, then you'll either want to use our (5.6+) or use vars($^V<5.6)

#!perl -w use strict; #Always! my $username=user; my $sessionid=1234; subone($comm); #in subroutines i could call subone { print "$comm->$username"; }

Replies are listed 'Best First'.
Re: Re: Persistent Variable
by Anonymous Monk on Jan 15, 2001 at 22:45 UTC
    It may not have been clear from my original post, but the subs themselves are in different package, that are being called by main, so they variables wouldn't be seen if I just declared them as globals.
      Actually, that's what I meant when I said, "If you have them in a namespace other then main::, then you'll either want to use our (5.6+) or use vars($^V<5.6)." With out playing games with the import() method or Exporter, you can get to package globals by fully specifying the package name. ie:
      use strict; # I can't emphasize that enough! { package Common; use vars qw/ $Var1 @Var2 /; $Var1 = "some value"; @Var2 = ( 1, 2, 3); if( $^V =~ m/^5\.6/ ) { our $Var3 = "The 5.6 way to do the above"; } } # Now in main:: name space print $Common::Var1; print reverse @Common::Var2;