[29139] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 383 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 26 14:09:38 2007

Date: Thu, 26 Apr 2007 11:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 26 Apr 2007     Volume: 11 Number: 383

Today's topics:
    Re: $ENV HOME on windows <nospam-abuse@ilyaz.org>
    Re: $ENV HOME on windows <1usa@llenroc.ude.invalid>
        Determining difference from Vista32 and Vista64 mpetersrx7@gmail.com
    Re: Management of Enterprise Computing <ignoramus3935@NOSPAM.3935.invalid>
    Re: Management of Enterprise Computing <uri@stemsystems.com>
        Readable/writable database in Perl <ecarlson@vmware.com>
    Re: SQL statement in Perl doesn't work <nobull67@gmail.com>
    Re: use one subroutine's variable value in another subr <glennj@ncf.ca>
    Re: use one subroutine's variable value in another subr <nobull67@gmail.com>
    Re: use one subroutine's variable value in another subr <injunjoel@hotmail.com>
    Re: use one subroutine's variable value in another subr <nobull67@gmail.com>
    Re: use one subroutine's variable value in another subr <paduille.4061.mumia.w+nospam@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 26 Apr 2007 15:31:49 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: $ENV HOME on windows
Message-Id: <f0qgl5$1893$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
A. Sinan Unur
<1usa@llenroc.ude.invalid>], who wrote in article <Xns991E5FEC1439Casu1cornelledu@127.0.0.1>:
> >> > What puzzles me deep is why Perl on Windows is not faking $ENV
> {HOME}
> >> > if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present...  I think 
> this

> > One of these should be $ENV{HOMEDRIVE}

Yeah, thanks.

> >> > would remove at least 10-20% of porting problems...

> Which might be a problem for those of us who create a D:\Home and move 
> users' 'My Documents' folders to directories under D:\Home\<userid> and 
> add a HOME variable to each user's environment. I am assuming such 
> problems can be avoided by checking for the existence of of $ENV{HOME} 
> before faking it.

Hmm, I thought that this would be clear without saying...  Sorry!

> However, this means that the check and the decision as 
> to whether to fake $ENV{HOME} should not be done at install time but 
> each time a script is run.

Each time the interpreter starts.

Hope this helps,
Ilya


------------------------------

Date: Thu, 26 Apr 2007 17:46:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: $ENV HOME on windows
Message-Id: <Xns991E8C2FB6A4Fasu1cornelledu@127.0.0.1>

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in
news:f0qgl5$1893$1@agate.berkeley.edu: 

> [A complimentary Cc of this posting was sent to
> A. Sinan Unur
> <1usa@llenroc.ude.invalid>], who wrote in article
> <Xns991E5FEC1439Casu1cornelledu@127.0.0.1>: 
 ...
>> I am assuming such problems can be avoided by checking for the
>> existence of of $ENV{HOME} before faking it.
> 
> Hmm, I thought that this would be clear without saying...  Sorry!
> 
>> However, this means that the check and the decision as 
>> to whether to fake $ENV{HOME} should not be done at install time but 
>> each time a script is run.
> 
> Each time the interpreter starts.

Looks like my post was a little redundant but thanks for the 
acknowledgement.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 26 Apr 2007 09:56:28 -0700
From: mpetersrx7@gmail.com
Subject: Determining difference from Vista32 and Vista64
Message-Id: <1177606588.371654.299810@r3g2000prh.googlegroups.com>

Is ther any way to determine in the running code the type of OS and
distinguish from 32-bit vs 64-bit Vista or XP.  I know the
Win32::GetOSVersion call but both the 32-bit and 64-bit of Vista
return the same thing for $major, $minor and $id.

Thanks,
Mark



------------------------------

Date: Thu, 26 Apr 2007 10:19:23 -0500
From: Ignoramus3935 <ignoramus3935@NOSPAM.3935.invalid>
Subject: Re: Management of Enterprise Computing
Message-Id: <rvOdnSCdk4JmX63bnZ2dnUVZ_vPinZ2d@giganews.com>

On Wed, 25 Apr 2007 23:26:50 -0400, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "i" == iguanodon  <iguanodon@guano.com> writes:
>
>  i> I have been tasked to create a system for managing enterprise
>  i> computing in our company. This would involve managing hundreds of
>  i> computers running our proprietary software, keeping an eye for
>  i> trouble, starting/restarting things, performing remote actions
>  i> conditionally based on success of other actions, etc.
>
>  i> All should be configurable and accept human input, etc.
>
>  i> We are going to use 'perl' for this and I would like to know what
>
> why is perl in quotes?
>
>  i> relevant perl modules could you recommend, for managing a lot of
>  i> computers at once, watching for stuff, etc.
>
> more than a list of modules you need someone who knows how to do
> this. why have you been 'tasked' with this when it seems to be over your
> head and you don't know perl? i recommend you hire someone.
>

I think that you are being a little presumptious about the OP's
abilities (e.g why do you know that the OP does not know perl), and
have not offered anything of value. That hardly helps this newsgroup
become a valuable resource. If you want to offer your own services, it
would be helpful to strike a little more humble position. 

i


------------------------------

Date: Thu, 26 Apr 2007 14:07:43 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Management of Enterprise Computing
Message-Id: <x73b2n80wg.fsf@mail.sysarch.com>

>>>>> "I" == Ignoramus3935  <ignoramus3935@NOSPAM.3935.invalid> writes:

  I> On Wed, 25 Apr 2007 23:26:50 -0400, Uri Guttman <uri@stemsystems.com> wrote:
  >>>>>>> "i" == iguanodon  <iguanodon@guano.com> writes:
  >> 
  i> I have been tasked to create a system for managing enterprise
  i> computing in our company. This would involve managing hundreds of
  i> computers running our proprietary software, keeping an eye for
  i> trouble, starting/restarting things, performing remote actions
  i> conditionally based on success of other actions, etc.
  >> 
  i> All should be configurable and accept human input, etc.
  >> 
  i> We are going to use 'perl' for this and I would like to know what
  >> 
  >> why is perl in quotes?
  >> 
  i> relevant perl modules could you recommend, for managing a lot of
  i> computers at once, watching for stuff, etc.
  >> 
  >> more than a list of modules you need someone who knows how to do
  >> this. why have you been 'tasked' with this when it seems to be over your
  >> head and you don't know perl? i recommend you hire someone.
  >> 

  I> I think that you are being a little presumptious about the OP's
  I> abilities (e.g why do you know that the OP does not know perl), and
  I> have not offered anything of value. That hardly helps this newsgroup
  I> become a valuable resource. If you want to offer your own services, it
  I> would be helpful to strike a little more humble position. 

i offered the advice to hire someone who knows how to do this. asking
for which perl modules support an enterprise management system is
clueless. you would need maybe 50 different modules and tons of glue
code to create such a beast and some serious perl skills (and multiple
hackers as well). so yes, i was presumptious but i bet fairly accurate
as well. notice how no one else even answered as there is no proper
answer to the exact question. moronzilla won't even jump in here but it
never uses cpan and knows nothing about IPC and large systems (hell, it
knows nothing about perl).

i would have offered my services to the OP but i am too busy and i doubt
someone so clueless would actually grasp that i would be of great value
to them for this even as an outside consultant/architect. they could
always read my signature and contact me. will i see a reply or even a
followup here? i wouldn't bet on it. but i am always open to new
projects and i do have the skills they need.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 26 Apr 2007 10:08:26 -0700
From: Eric <ecarlson@vmware.com>
Subject: Readable/writable database in Perl
Message-Id: <1177607306.259802.191810@o40g2000prh.googlegroups.com>

Hello,

Currently, our code is utilizing a database that is neither humanly
readable or writable. My task is to modify the existing code so that
the database is both. A sample of the code is below - in this
particular example, to request a mount point. (It does some other
stuff, such as incrementing/decrementing counts, etc., but that can be
ignored in relation to this request for assistance.)

I'm not looking for the solution in the posting (that wouldn't be any
fun :); what I am looking for is some initial direction on how I might
go about accomplishing this. There are no shortage of database related
core and CPAN modules. In particular, I was told to use the 'mySQL'
approach (if that means anything to anybody).

Anyone have an idea on how I might go about this task?

Thanks to advance to all that respond.

Eric

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
sub RequestMountPoint {
   my $self = shift;
   my $protocol = shift;
   my $bldNum = shift;
   my $mntPnt = undef;
   my $mntDBfile = $self->Config->HomeDir()."/mntDBfile";

   my $mntsDB = {};
   unless (open SEMAPHORE, "> /tmp/mnt.lock") {
      $self->Config->Env->ReleaseMach();
      die "problem allocating semaphore";
   }
   flock SEMAPHORE, Fcntl::LOCK_EX;

   tie( %$mntsDB, "MLDBM", $mountsDBFile, O_CREAT|O_RDWR, 0666,
$DB_File::DB_BTREE );

   my $mountPoint = $self->Config->MountPointCount();
   for (my $label = 0; $label < $mountPoint; $label++){
      $mntPnt = "mntpnt".$label;
      unless (defined($mntsDB->{$mntPnt})){
         $mntsDB->{$mntPnt} = {
                                 BldNum => $bldNum,
                                 Protocol => $protocol,
                                 RefCnt => 1,
                              };
         last;
      }

      if (($mntsDB->{$mntPnt}->{BldNum} == $bldNum) and
          ($mntsDB->{$mntPnt}->{Protocol} eq $protocol)) {
         $mntsDB->{$mntPnt}->{RefCnt}++;
         last;
      }

      $mntPnt = undef;
   }
   my $ref = $mntsDB->{$mntPnt}->{RefCnt};

   untie(%$mntsDB);

   close(SEMAPHORE);

   return $mntPnt, $ref;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



------------------------------

Date: 26 Apr 2007 10:47:42 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: SQL statement in Perl doesn't work
Message-Id: <1177609662.699259.141640@n15g2000prd.googlegroups.com>

On Apr 26, 2:46 pm, Huub <"v.niekerk at hccnet.nl"> wrote:
> Hi,
>
> I have written a script that reads from a MySQL database. It works fine,
> except that the addition of one AND does not work while it does in Query
> Browser:
>
> select betaald2006 from hvw where lidnr = $record and naam != " " and
> kenmerk2006 is null
>
> works. The same statement via Perl:
>
> $betaald2006 = "select betaald2006 from hvw where lidnr = $record and
> naam != ' ' and kenmerk2006 is null";

That's just a string. It may _look_ to you like an SQL query but
there's nothing in your code to cause that to be sent to a database
engine. It's just a string.

> does not work.

Never say "it does not work".

> When I remove "and kenmerk2006 is null", it works ok.

Never say "it works ok".

> With it, I don't get a real error, just this message about $betaald2006:
>
> "Use of uninitialized value in string eq"
> in
>
> "if ($betaald2006 eq $vergelijk)"

I do not believe you.

If you've just put a string in $betaald2006 then it would not be
undefined. I suspect there are further statements between  the two you
showed us. Either that or $vergelijk is undefined.

> Any idea what I'm doing wrong?

You are posting to comp.lang.perl.misc without reading the posting
guidelines.



------------------------------

Date: 26 Apr 2007 16:51:34 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <slrnf31m4n.8fm.glennj@smeagol.ncf.ca>

At 2007-04-26 09:28AM, "king" wrote:
[...]
>  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;

How do you call get_course_info() ? 

Are you aware that @years and @template_subject_period will only contain
one element each?  

Read perldoc perlsub to note that parameters passed to a subroutine are
flattened into a single list of scalars.  

If you call get_course_info like this:
    $foo->get_course_info(1, (2, 3, 4), 5, 6, (7, 8, 9))
then the @_ array will contain
    (1, 2, 3, 4, 5, 6, 7, 8, 9) 
Then you use shift() to assign parameters which only takes the first
element out of @_.  So,
    $subject_name is 1
    @years is (2)
    $periods is 3
    $count is 4
    @template_subject_period is (5)
    @_ is (6, 7, 8, 9)


-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


------------------------------

Date: 26 Apr 2007 10:08:10 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <1177607290.204961.88430@t38g2000prd.googlegroups.com>

On Apr 26, 2:28 pm, king <hara.acha...@gmail.com> 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;

> }
>
> sub get_course_info
> {
         my $self = shift;
        # 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.



------------------------------

Date: 26 Apr 2007 10:35:00 -0700
From: injunjoel <injunjoel@hotmail.com>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <1177608900.830802.143600@u32g2000prd.googlegroups.com>

Greetings,
Here are my suggestions based on what I understood from your post.
Read the comments at the bottom for more details.

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

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

        # load school types from config file
        $self->load_school_template();

	#From the looks of it you don't need to call this
	#when you create the object so leave it out.
	#$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]);

				#you created a blessed hash for your object structure... USE
IT!							     #here we nest a bunch of stuff in the object hash
				#	$self->{'subject_period'}  contains a hash with
				#		$subject_name as keys which contains a hash with
				#			@years as keys so 'periods_1','periods_2', etc...
				#				with a array of what ever came out of $periods
				#
				#this is all to facilitate your lookup in get_course_info();
                                push (@{$self->{'subject_period'}-
>{$subject_name}->{$years[$count]}}, $periods);
                        }
                }
        }
	return 1;
}

sub get_course_info
{

# This is now just a method of the underlying object hash
# call it with the subject name as the only argument


        my $self = shift;
        my $subject_name = shift;
        print "Please enter period to get subject and number of
periods \n";
        my $gotperiod = <>;
        chomp($gotperiod);

	#lets check shall we?
	if($gotperiod < 1 || $gotperiod > 5)
	{
			print "Period out of range.\nValid range is 1-5!\n";
			return undef;
	}

	#standardize the periods key if they only entered a number.
	$gotperiod = 'periods_'.$gotperiod if($gotperiod !~ /^periods_/);

        #check if this is even a valid key/subject
	if(exists($self->{'subject_period'}->{$subject_name}))
	{
		#do the lookup for this subject.
		my @courses = @{$self->{'subject_period'}->{$subject_name}-
>{$gotperiod}};

		#print what we found from our lookup.
		foreach my $course (@courses)
		{
	        	print "Subject:\t" . $subject_name .  . "\n";
		}
	}
	else {
		print "Subject: $subject_name was not found!\n";
		return undef;
	}

        return 1;
}

sub get_subject_names
{
	$self = shift;
	return sort {$a cmp $b} keys @{$self->{'subject_period'}};
}

1;


#
#	sample usage:
#		my $obj = TPWizardMgr->new();
#		my @subjects = $obj->get_subject_names;
#		foreach my $subject (@subjects)
#		{
#			$obj->get_course_info($subject);
#		}
#
#
#
#


==========================================================================



On Apr 26, 6:28 am, king <hara.acha...@gmail.com> wrote:
> 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.




------------------------------

Date: 26 Apr 2007 10:40:08 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <1177609208.844234.259040@t39g2000prd.googlegroups.com>

On Apr 26, 2:28 pm, king <hara.acha...@gmail.com> wrote:
> I have a module named TPWizardMgr.pm as below.
>
> ========================================================================
> package TPWizardMgr;
> use strict;

Good, but you forgot "use warnings".  Even tying only one hand behind
your back makes life difficult.
> use XML::DOM;

> sub new
> {
>         my $class = shift;
>         my $self = {};
>         bless $self, $class;
>
>         # reset all data
>         $self->{load_school_template} = {};
>         $self->{get_course_info} = {};

Why?

>         # load school types from config file

A comment should describe things about what the code is doing that are
not obvious from looking at it.

It should not describe things about what the code is doing that are
obvious from looking at it.

It should not assert that the code is doing something that it's not.

>         $self->{load_school_template} = [];
>         $self->{get_course_info} = [];

What!?

>         return $self;
>
> }
>
> sub load_school_template
> {
>         my $self = shift;
>         my $len ;
>         my $item;
>         my @years;
>         my $periods;
>         my $subject_name;
>         my @template_subject_period;

That's a very very nasty case of premature declaration you've got
there. You should take something for it.

>         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');

@years seems a perverse name for a variable containing that data.

Since that's a constant expression you should take the assignment
outside the loop.

>                         for(my $i = 0;$i<$len;$i++)
>                         {
>                                 $item = $school_template->getElementsByTagName('subject-template')->item($i);
>

You used a foreach just a few lines up, how come you've forgotten it
so soon?

        foreach my $item ($school_template-
>getElementsByTagName('subject-template')


>                                 $subject_name = $item->getAttribute('name');
>
>                                 for my $count (0..4)
>                                 {
>                                         $periods = $item->getAttribute($years[$count]);

And again

        foreach my $year (@years)
        {
             my $periods = $item->getAttribute($year);


>
>         return @template_subject_period;

You probably should not return the contents of
@template_subject_period (which could be big) but rather a reference
to @template_subject_period (which is just one value).

> }
>
> sub get_course_info
> {
>         my $self = shift;
>         my $subject_name = shift;
>         my @years = shift;

You are storing a single argument in the array @years. What was it you
intended to do?

>         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++)

Again with the C-style for!

>                 {
>                 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};

You never put anything is $self->{get_course_info} execpt []. So
what's the point?
>
> }

Sorry that subroutine is just too confused - I am unable to guess what
you were trying to do.

Here's what a cleaned up new() and load_school_template() might look
like but I can't help with get_course_info...

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

sub load_school_template
{
    my $self = shift;
    my $parser = new XML::DOM::Parser;

    $self->{template_subject_period} = my $template_subject_period =
[];

    my $doc = $parser->parsefile ("/usr/local/apache2/wizard_data/
liceo_classico.xml");
    my @years =
	('periods_1','periods_2','periods_3','periods_4','periods_5');

    foreach my $school_template($doc->getElementsByTagName('subject-
templates'))
    {
	foreach my $item ($school_template->getElementsByTagName('subject-
template')) {
	    my $subject_name = $item->getAttribute('name');
	    foreach my $year ( @years ) {
		my $periods = $item->getAttribute($year);

		push
		    @$template_subject_period,
		    [$subject_name,$year, $periods]);
	}
    }
    return $template_subject_period;
}



------------------------------

Date: Thu, 26 Apr 2007 15:32:36 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <oC3Yh.3987$Ut6.138@newsread1.news.pas.earthlink.net>

On 04/26/2007 08:28 AM, king wrote:
> I have a module named TPWizardMgr.pm as below.
> [ 50+ lines of code snipped ]
> 
> 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.
> 

Since @template_subject_period was declared with "my," it is restricted 
to the scope of get_course_info. The solution is to make the variable a 
package variable; declare it with "our."

You can access the variable from other packages as 
@TPWizardMgr::template_subject_period. Since you're creating a class, a 
more object oriented approach would be to make the variable accessible 
through a class method, e.g:

sub template_subject_period {
   my $class = shift;
   our @template_subject_period;
   return \@template_subject_period;
}

Since the above method returns an array reference, you would have to be 
comfortable using array references. If not, just use the other solution 
above.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 383
**************************************


home help back first fref pref prev next nref lref last post