I'm coming from an OO background and had a question about
keeping a persistent variable. For those familar with java,
you know that you can instantiate a class and have variables
associated with that class that you can assign and retrieve
values for.
Here's the perl question. I have a main script that checks
the cgi params and calls subroutines according to the params.
Each subroutine outputs html code that includes the users
sessionid and username. Can I have a perl package that would
keep track of the username sessionid so that I could reference
there values in my subroutines? Or do I have to pass the values,
of the sessionid and username to each of the subroutines when
I call them.
I was envisioning something like this.
package Common;
{
my $username,$sessionid;
}
###
#set their values in the main code
$comm=new Common;
$comm->$username=user;
$comm->$sessionid=1234;
subone($comm);
#in subroutines i could call
subone
{
print "$comm->$username";
}
Is there a practical way of doing this? Anyway to do it
without even having to pass the $comm to the subroutines?
Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.