use one subroutine's variable value in another subroutine inside a module.



I have a module named TPWizardMgr.pm as below.

========================================================================
package TPWizardMgr;
use strict;
use XML::DOM;

sub new
{
my $class = shift;
my $self = {};
bless $self, $class;

# reset all data
$self->{load_school_template} = {};
$self->{get_course_info} = {};

# load school types from config file
$self->{load_school_template} = [];
$self->{get_course_info} = [];

return $self;
}


sub load_school_template
{
my $self = shift;
my $len ;
my $item;
my @years;
my $periods;
my $subject_name;
my @template_subject_period;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("/usr/local/apache2/wizard_data/
liceo_classico.xml");

foreach my $school_template($doc-
getElementsByTagName('subject-templates'))
{
$len = $school_template-
getElementsByTagName('subject-template')->getLength() ;
@years =
('periods_1','periods_2','periods_3','periods_4','periods_5');
for(my $i = 0;$i<$len;$i++)
{
$item = $school_template-
getElementsByTagName('subject-template')->item($i);
$subject_name = $item-
getAttribute('name');
for my $count (0..4)
{
$periods = $item-
getAttribute($years[$count]);
push
(@template_subject_period, [$subject_name,$years[$count], $periods]);
}
}
}

return @template_subject_period;
}

sub get_course_info
{
my $self = shift;
my $subject_name = shift;
my @years = shift;
my $periods = shift;
my $count = shift;
my @template_subject_period = shift;
print "Please enter period to get subject and number of
periods \n";
my $gotperiod = <>;
chomp($gotperiod);
for(my $i=0;$i <= $#template_subject_period;$i++)
{
print $#template_subject_period . "\n";
print "inside for loop\n";
if($template_subject_period[$i]->[1] eq $gotperiod)
{
push (@template_subject_period,
[$subject_name,$years[$count], $periods]);

print "Subject:\t" .
$template_subject_period[$i]->[0] . $template_subject_period[$i]-
[2] . "\n";
}
}
return $self->{get_course_info};
}

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.

How I can do this.

Thanks in advance.

.



Relevant Pages

  • Re: Question about scope.
    ... > I am trying to create an class and then try to access the data members ... shift that off, for later use. ... Just return the result of bless(). ... reference, so if you close the sub just after bless, that is ...
    (comp.lang.perl.misc)
  • sitemap generator for Perl
    ... I want to run the sitemap generator ... Returns the minimum number of links to traverse from the root URL of ... my $class = shift; ...
    (perl.beginners)
  • Re: Replacing a line
    ... #Using core module Tie::File to process a file in this subroutine ... sub process_one_file { ... $cpp_file = shift; ... for (@array) #Each line should come one by one ...
    (comp.lang.perl.misc)
  • Re: Threads and OO Question
    ... > " bless is not supported on shared references. ... sub increment { ... package MyPackage; ... my $class = shift; ...
    (comp.lang.perl.misc)
  • subroutine in LWP - in order to get 700 forum threads
    ... sub get_threads { ... my $page = shift; ... push @links, values %attr; ... This must get a subroutine - doesn t it? ...
    (perl.beginners)