Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using one methods variable value in another method inside a module

Reply
Thread Tools

Using one methods variable value in another method inside a module

 
 
king
Guest
Posts: n/a
 
      04-29-2007
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:OM;

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:OM:arser;
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;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using object methods of first module in methods of second module Nikita Petrov Ruby 2 04-06-2008 08:49 PM
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Change value of one variable based on user input of another value TeknoShock Javascript 1 12-01-2006 05:06 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments