Re: use one subroutine's variable value in another subroutine inside a module.
- From: Brian McCauley <nobull67@xxxxxxxxx>
- Date: 26 Apr 2007 10:08:10 -0700
On Apr 26, 2:28 pm, king <hara.acha...@xxxxxxxxx> wrote:
I have a module named TPWizardMgr.pm as below.
sub load_school_template#...
{
my $self = shift;
my @template_subject_period;# Put lots of stuff in @template_subject_period;
}my $self = shift;
sub get_course_info
{
# Stuff that needs @template_subject_period calculated above
}
1;
==================================================================
But I want to use the variable @template_subject_period in the
subroutine get_course_info( ).
I am not able to use this @template_subject_period variable value in
the get_course_info subroutine.
No because it's lexically scoped to the other subroutine.
If you want data that persists from one method call to another you
store it _in_the_object_.
How I can do this.
sub load_school_template
{
my $self = shift;
#...
# Put lots of stuff in @{$self->{template_subject_period}};
}
sub get_course_info
{
my $self = shift;
# Stuff that uses @{$self->{template_subject_period}};
}
Now I've answered the question you asked I'll compose another follow-
up that addresses some other issues with your code.
.
- References:
- Prev by Date: Determining difference from Vista32 and Vista64
- Next by Date: Readable/writable database in Perl
- Previous by thread: Re: use one subroutine's variable value in another subroutine inside a module.
- Next by thread: Re: use one subroutine's variable value in another subroutine inside a module.
- Index(es):
Relevant Pages
|