Using one methods variable value in another method inside a module

K

king

The below script if I am writing in a script its working fine but I
want to make this a module.

As the subroutine this (load_school_template ) will store the values
and

the get_course_info will display the values.
But I am not clear about the reference so I am using simple array that
is @template_subject_period. And by using the
same @template_subject_period array in the get_course_info subroutine
I am getting the output as name of the subject and number of periods
by giving input the no of years.

But inside the get_course_info method the @template_subject_period
value is not used.

My requirement is the get_course_info method should give out put as
the subject name and the no. of periods when
i will give input as "periods_1" or periods_2" etc..

this is the XML file from which I am getting the out put.name :
school.xml
===========================================================================
<?xml version="1.0" ?>
<school-template>
<class-templates>
<class-template marker="1" name="4 *" />
<class-template marker="2" name="5 *" />
<class-template marker="3" name="1 *" />
<class-template marker="4" name="2 *" />
<class-template marker="5" name="3 *" />
</class-templates>
<subject-templates>
<subject-template name="maths" periods_1="5" periods_2="5"
periods_3="4" periods_4="4" periods_5="4" />
<subject-template name="geography" periods_1="5" periods_2="5"
periods_3="4" periods_4="4" periods_5="4" />
<subject-template name="physics" periods_1="4" periods_2="4"
periods_3="3" periods_4="3" periods_5="3" />
<subject-template name="chemistry" periods_1="4" periods_2="4"
periods_3="-" periods_4="-" periods_5="-" />
<subject-template name="science" periods_1="2" periods_2="2"
periods_3="3" periods_4="3" periods_5="3" />
</subject-templates>
</school-template>

===========================================================================
this is the module i want to make: name: TPWizardMgr.pm
=======================================================================
package TPWizardMgr;
use strict;
use XML::DOM;

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


# load school types from config file
$self->{school_types} = [];
$self->load_config($CONFIG_FILE);
$self->{load_school_template} = [];
return $self;
}


sub load_school_template
{
my $self = shift;
my $len ;
my $item;
my @years;
my $periods;
my $subject_name;
our @template_subject_period;
my $parser = new XML::DOM::parser;
my $doc = $parser->parsefile ("/usr/local/apache2/wizard_data/
school.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]);

}
}
}

$doc->dispose();
}

sub get_course_info
{
my $self = shift;
my $subject_name = shift;
my @years = shift;
my $periods = shift;
my $count = 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 $#{$self->{load_school_template}. "\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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top