[29147] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 391 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 29 03:10:20 2007

Date: Sun, 29 Apr 2007 00:09:07 -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           Sun, 29 Apr 2007     Volume: 11 Number: 391

Today's topics:
    Re: Can a network client specify an IP on the source si yong321@yahoo.com
    Re: Correlating Data from same .csv, line by line <joe@inwap.com>
        Lawyer Resources Leisure.213@gmail.com
        new CPAN modules on Sun Apr 29 2007 (Randal Schwartz)
        Problem with Image::Info <gsvdl@yahoo.com>
    Re: Problem with Image::Info <no@email.com>
    Re: Rounding up to the next .5 <justin.0704@purestblue.com>
    Re: Rounding up to the next .5 anno4000@radom.zrz.tu-berlin.de
    Re: Rounding up to the next .5 <tadmc@augustmail.com>
    Re: Samba file access checking? <joe@inwap.com>
    Re: SQL statement in Perl doesn't work <joe@inwap.com>
    Re: Top Turds of comp.lang.perl.misc (2007) <m@rtij.nl.invlalid>
    Re: use one subroutine's variable value in another subr <hara.acharya@gmail.com>
    Re: UTF8 European characters in MySQL <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Apr 2007 21:44:31 -0700
From: yong321@yahoo.com
Subject: Re: Can a network client specify an IP on the source side?
Message-Id: <1177821871.686932.85120@n76g2000hsh.googlegroups.com>

On Apr 28, 10:34 pm, yong...@yahoo.com wrote:
> When I initiate a network connection to a remote server, is there a
> way to specify an IP address on the source side? Take a Perl snippet
> as an example (modified from "Programming Perl"):
>
> #!/usr/local/bin/perl -w
> require 5.002;
> use Socket;
>
> $remote = shift || 'locahost';
> $port = shift || 2345;
> $iaddr = inet_aton($remote) or die "No host: $remote";
> $paddr = sockaddr_in($port, $iaddr);
> $proto = getprotobyname("tcp");
> socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
>
> #Does it make sense to bind the socket with an IP on the source? How?
> bind(SOCK, sockaddr_in(0, "10.6.143.111")) or die "bind: $!";
>
> connect(SOCK, $paddr) or die "connect: $!";
> print while <SOCK>;
> close SOCK or die "close: $!";
> exit;
>
> I've never seen a bind() call on a client. I added it because I want
> to designate a specific IP on a multihomed server. But it throws
> error:
>
> $ client.pl some.destination.example.com 22
> bind: Cannot assign requested address at client.pl line <line number
> pointing to the bind() line>.
>
> That IP does exist as shown in ifconfig output. I suspect the first
> argument to sockaddr() should not be 0. Any help is appreacited.
>
> Yong Huang
> [This message was posted to another group without a definitive answer]

In case anybody is interested, this works, thanks to liyimin41's
offline help:

bind(SOCK,sockaddr_in(0,inet_aton("10.6.143.111"))) or die "bind: $!";

Yong Huang



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

Date: Sat, 28 Apr 2007 23:36:52 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Correlating Data from same .csv, line by line
Message-Id: <yNmdnccZb9OaoKnbnZ2dnUVZ_rOqnZ2d@comcast.com>

shadkeene@hotmail.com wrote:
> Here's a complete but minimal example...

That's not a complete example.  A complete example is one that I can
copy-an-paste from your posting and execute to reproduce your problem
on my machine.  It has to be complete enough to compile with
"use strict; use warnings;" and include any data it needs to run.

The act of reducing the problem down to the point where it can be executed
on another person's computer will often make the error glaringly obvious.
Try it.

	-Joe


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

Date: 28 Apr 2007 18:43:44 -0700
From: Leisure.213@gmail.com
Subject: Lawyer Resources
Message-Id: <1177811024.278729.255960@n59g2000hsh.googlegroups.com>

Free Lawyer Resource Journal http://lawyersblog.blogspot.com/



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

Date: Sun, 29 Apr 2007 04:42:10 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Apr 29 2007
Message-Id: <JH8t2A.1oGF@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Buffy-1.5
http://search.cpan.org/~lbrocard/Acme-Buffy-1.5/
An encoding scheme for Buffy the Vampire Slayer fans
----
Acme-Colour-1.04
http://search.cpan.org/~lbrocard/Acme-Colour-1.04/
additive and subtractive human-readable colours
----
CGI-Application-Gallery-1.02
http://search.cpan.org/~leocharre/CGI-Application-Gallery-1.02/
----
Catalyst-Controller-PathArgs-0.1
http://search.cpan.org/~zby/Catalyst-Controller-PathArgs-0.1/
syntactic sugar for Catalyst::DispatchType::Chained.
----
Catalyst-Plugin-Log-Colorful-0.01
http://search.cpan.org/~tomyhero/Catalyst-Plugin-Log-Colorful-0.01/
Catalyst Plugin for Colorful Log
----
DateTime-Format-Natural-0.30
http://search.cpan.org/~schubiger/DateTime-Format-Natural-0.30/
Create machine readable date/time with natural parsing logic
----
Devel-StackTrace-1.15
http://search.cpan.org/~drolsky/Devel-StackTrace-1.15/
Stack trace and stack trace frame objects
----
Devel-ebug-Wx-0.08
http://search.cpan.org/~mbarbon/Devel-ebug-Wx-0.08/
GUI interface for your (d)ebugging needs
----
Games-WoW-Armory-0.0.3
http://search.cpan.org/~franckc/Games-WoW-Armory-0.0.3/
Access to the WoW Armory
----
HTML-ListScraper-0.03
http://search.cpan.org/~vbar/HTML-ListScraper-0.03/
generic web page scraping support
----
HTML2XHTML-0.03.08a
http://search.cpan.org/~oembry/HTML2XHTML-0.03.08a/
Wrapper to command-line program that converts from HTML 3.x/4.x to XHTML 1.0
----
HTML2XHTML-0.03.08b
http://search.cpan.org/~oembry/HTML2XHTML-0.03.08b/
Wrapper to command-line program that converts from HTML 3.x/4.x to XHTML 1.0
----
Heap-0.80
http://search.cpan.org/~jmm/Heap-0.80/
Perl extensions for keeping data partially sorted
----
JavaScript-JSLint-0.06
http://search.cpan.org/~hdm/JavaScript-JSLint-0.06/
Check JavaScript code for problems
----
MediaWiki-1.1
http://search.cpan.org/~spectrum/MediaWiki-1.1/
OOP MediaWiki engine client
----
MediaWiki-1.10
http://search.cpan.org/~spectrum/MediaWiki-1.10/
OOP MediaWiki engine client
----
Module-Build-0.2808
http://search.cpan.org/~kwilliams/Module-Build-0.2808/
Build and install Perl modules
----
Module-Packaged-Report-0.01
http://search.cpan.org/~szabgab/Module-Packaged-Report-0.01/
Generate report upon packages of CPAN distributions
----
Modwheel-0.2.3
http://search.cpan.org/~asksh/Modwheel-0.2.3/
Very extensible publishing-system
----
Net-SFTP-Foreign-0.90_22
http://search.cpan.org/~salva/Net-SFTP-Foreign-0.90_22/
Secure File Transfer Protocol client
----
PGP-Sign-0.20
http://search.cpan.org/~rra/PGP-Sign-0.20/
Create detached PGP signatures for data, securely
----
POE-Component-DirWatch-Object-0.08
http://search.cpan.org/~groditi/POE-Component-DirWatch-Object-0.08/
POE directory watcher object
----
POE-Component-DirWatch-Object-0.09
http://search.cpan.org/~groditi/POE-Component-DirWatch-Object-0.09/
POE directory watcher object
----
Parse-QTEDI-0.10
http://search.cpan.org/~dongxu/Parse-QTEDI-0.10/
Parse QT/KDE preprocessed headers
----
WWW-Wow-RealmStatus-0.01
http://search.cpan.org/~sock/WWW-Wow-RealmStatus-0.01/
The great new WWW::Wow::RealmStatus!
----
Weed-0.0014
http://search.cpan.org/~hooo/Weed-0.0014/
ist ein englisches Wort f?r Unkraut
----
Weed-0.0016
http://search.cpan.org/~hooo/Weed-0.0016/
ist ein englisches Wort f?r Unkraut
----
Weed-0.0017
http://search.cpan.org/~hooo/Weed-0.0017/
ist ein englisches Wort f?r Unkraut
----
Wx-0.74
http://search.cpan.org/~mbarbon/Wx-0.74/
interface to the wxWidgets cross-platform GUI toolkit
----
Wx-Perl-ListView-0.01
http://search.cpan.org/~mbarbon/Wx-Perl-ListView-0.01/
virtual list control interface
----
Wx-Perl-TreeView-0.02
http://search.cpan.org/~mbarbon/Wx-Perl-TreeView-0.02/
virtual tree control interface


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 28 Apr 2007 13:07:56 -0700
From: Gary <gsvdl@yahoo.com>
Subject: Problem with Image::Info
Message-Id: <1177790876.555421.255970@n59g2000hsh.googlegroups.com>

I am trying to write a perl cgi script using Image::Info.  The problem
is
I am not getting any info from Image::Info.  The hash comes back
empty.
If I reduce my script down to what is shown below the page that gets
displayed
only has the photo.  If the hash wasn't empty "Good" should be
displayed above
the photo.  I have never used Image::Info before.  I am using the
module
description in CPAN,  there are no error messages in the browser
error log and the page is being displayed.  Are there any suggestions?

Gary

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
use Image::Info qw(image_info dim);

my $Photo = param('photo');
my $info = image_info("$Photo");

print header;
print start_html(-title=>'My Photos',  -bgcolor=>'#FFDEAD');

if (%info){
print "Good <br> \n";
}

print "<img SRC=\"$Photo\"/>",
print end_html;



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

Date: Sat, 28 Apr 2007 21:40:37 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Problem with Image::Info
Message-Id: <59hpq5F2l3cajU1@mid.individual.net>

Gary wrote:

> #!/usr/bin/perl -w
> use strict;
> use CGI qw(:standard);
> use Image::Info qw(image_info dim);
> 
> my $Photo = param('photo');
> my $info = image_info("$Photo");
> 
> print header;
> print start_html(-title=>'My Photos',  -bgcolor=>'#FFDEAD');
> 
> if (%info){
> print "Good <br> \n";
> }
> 
> print "<img SRC=\"$Photo\"/>",
> print end_html;


$ perl tmp119.pl
Global symbol "%info" requires explicit package name at tmp119.pl line 12.
Execution of tmp119.pl aborted due to compilation errors.


I assume $info is a reference to a hash, in which case you need to read
perldoc perlref


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: Sat, 28 Apr 2007 20:36:18 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Rounding up to the next .5
Message-Id: <slrnf37c23.p8.justin.0704@justin-catteralls-computer.local>

In article <AIKYh.2898$r77.978@trndny08>, Jürgen Exner wrote:
> Justin C wrote:
>> I'm writing a utility for work that will calculate the price to send a
>> parcel. The courier charges by the half kilo and they never round
>> down.
>>
>> I'm trying to round weights (with up to two decimal places) up to the
>> next half kilo (unless the weight is an exact or .5 kilo already).
> 
> I think you are making this waaaay to complicated.

Sometimes you're too busy following logic to see the lateral.


> For one I am pretty sure there are modules on CPAN that do floor() and 
> ceiling() functions.

There are that, and, IIRC (from today's Googling for a round() function)
they are part of POSIX, and therefore (if my understanding is correct) 
already installed.

Trouble is, I don't know what those are/do, perldoc wasn't much help, 
I suppose they're mathematical functions, I didn't get that far with my
education and so didn't understand, and perldoc -q round, though it 
mentioned those, didn't explain them in a way I'd understand that they
are relevant to my problem.


> And second there are really only three simple cases that you need to 
> distinguish:
> 
> if the decimal portion is 0 then the shipping weight is the actual weight
> If 0 < decimal portion <= 0.5 then the shipping weight is the integer part 
> plus 0.5
> If 0.5 < decimal portion then the shipping weight is the integer part plus 1

Now that's a lateral solution to the problem. I'm pretty sure I can 
manage that too!

JŸrgen, thank you for your help.

	Justin.

-- 
Justin C, by the sea.


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

Date: 28 Apr 2007 22:47:45 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Rounding up to the next .5
Message-Id: <59i18hF2l1l86U1@mid.dfncis.de>

Justin C  <justin.news@purestblue.com> wrote in comp.lang.perl.misc:
> 
> Not strictly a perl problem, I'm just happen to be using perl to do
> this.
> 
> I'm writing a utility for work that will calculate the price to send a
> parcel. The courier charges by the half kilo and they never round down.
> 
> I'm trying to round weights (with up to two decimal places) up to the
> next half kilo (unless the weight is an exact or .5 kilo already).
> 
> I've looked at the 'round' in the docs. You can round, for example, four
> decimal places to three, two, one, or none, but there's no mention of
> rounding, say, .3 to .5.

You can base one on the other.  Rounding to the nearest half can be
seen as multiplying by two, then rounding to the nearest integer,
then dividing by two again.  Generalizing, you get

    sub round_to_multiple {
        my ( $x, $factor) = @_;
        $factor*sprintf '%.0f', $x/$factor;
    }

which can be used as

    for ( map 0.1*$_, 0 .. 10 ) {
        printf "%s -> %s\n", $_, round_to_multiple( $_, 1/2);
    }

Anno


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

Date: Sat, 28 Apr 2007 19:24:36 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Rounding up to the next .5
Message-Id: <slrnf37pe4.d3t.tadmc@tadmc30.august.net>

Justin C <justin.0704@purestblue.com> wrote:
> In article <AIKYh.2898$r77.978@trndny08>, Jürgen Exner wrote:
>> Justin C wrote:

>>> I'm trying to round weights (with up to two decimal places) up to the
>>> next half kilo (unless the weight is an exact or .5 kilo already).

>> For one I am pretty sure there are modules on CPAN that do floor() and 
>> ceiling() functions.
>
> There are that, and, IIRC (from today's Googling for a round() function)
> they are part of POSIX, and therefore (if my understanding is correct) 
> already installed.
>
> Trouble is, I don't know what those are/do, perldoc wasn't much help, 
> I suppose they're mathematical functions, I didn't get that far with my
> education and so didn't understand, 


   http://en.wikipedia.org/wiki/Ceiling_function


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 28 Apr 2007 23:29:59 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Samba file access checking?
Message-Id: <q5udnZaPlKn0pqnbnZ2dnUVZ_hOdnZ2d@comcast.com>

Jim Ford wrote:
> I'm checking Samba share files accessed on my Linux machine, using the 
> output of smbstatus to get the IP addresses of the machines. This seems 
> to me to be a kludgy way of doing it

What are you trying to accomplish?
   *) Get the IP address of a file server
   *) Get a list of shares available from file servers
   *) Check that a specific share is writable by a particular client
?


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

Date: Sat, 28 Apr 2007 23:07:12 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: SQL statement in Perl doesn't work
Message-Id: <y8udnRRleqSIq6nbnZ2dnUVZ_gKdnZ2d@comcast.com>

Huub wrote:

> if ($betaald2006 eq $vergelijk)
> {
> 
> And the warning I posted does point to the "if" line.

I see that you've found the answer to your problem, but I want to point out
something.  You did not indicate whether or not there is an "elsif" clause
on your "if" statement.  That can make a difference when debugging.

In an "if" statement with an "elsif" part, uninitialized variables detected in
the "elsif" part will be reported with the line number of the "if" part.



linux% cat -n test.pl
      1  use strict; use warnings;
      2  my($foo,$bar);
      3  if ($foo == 1) {
      4    print "foo is one\n";
      5  } elsif ($bar eq 'two') {
      6    print "bar is two\n";
      7  } else {
      8    print "none of the above\n";
      9  }
linux% perl test.pl
Use of uninitialized value in numeric eq (==) at test.pl line 3.
Use of uninitialized value in string eq at test.pl line 3.
none of the above

The string eq line 5 is considered to be a part of the if statement
that started at line 3.

	-Joe


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

Date: Sat, 28 Apr 2007 21:37:46 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <pan.2007.04.28.19.38.20@rtij.nl.invlalid>

On Fri, 13 Apr 2007 12:31:17 -0700, cartercc wrote:

> On Apr 12, 8:45 pm, Tad McClellan <t...@augustmail.com> wrote:
>> The decline in traffic is due to greater overall efficiency!
> 
> Actually, it's because Perl is dying.
> 
> People are using other languages, Java, PHP, and in my area, Python. We
> still use a good amount of Perl, in fact, I'm engaged in a fairly large
> database automation program which will probably use about 15 or so Perl
> scripts. But serious developers will use Java, or even VB (yes, even VB)
> rather than Perl, at least in my community.
> 
> If you want to get laughed at, use Perl. It's so ... 80's.

Well, just had another look at python today. While I have some serious 
reservations, I can see why it is so popular. For one, it's actually 
quite readable.(This comes from someone who has programmed for 20 years 
in all kinds of languages. Yes, even prolog for those who remember that.)

There are so many tools to get the job done today. Perl is in a competing 
arena where there are good arguments to use other languages.

However, many of those arguments have to do with maintainability, not 
capability. And maintainability has to do with the skills of programmers, 
not language capabilities.

To go into the very languages you state:
* Python: A very good competitor. Con, not installed by default on many 
OSses. Pro: Can do about anything that Perl can, in a more readable way.
* VB: Is not used very much, except in Windows only shops (which are 
many). In todays webcentric environments, VB is only used for intranet 
applications and cannot be taken very seriously because of it's 
maintenance issues (much of those are actually really more a programmer/
management issue (we use MS only!) than a real coding issue).
* Java: Java was the hype. Nowadays I see it used a lot, but in very 
specific circumstances:
  1) Web programming: There's lot of serious webprogramming in Java. If 
you want a serious framework for large projects, don't look at Perl, Java 
is much better suited. However, for small projects, Java is just 
overkill, use Perl, php, or whatever small solution.
  2) Specific clients. They are slow, but they work. hey, if you can 
overcome the write once test anywhere conundrum, Java is ideal. It's much 
better than writing specific clients for all OSses you are targetting. 
Perl is no contestor in this area, except specific clients written for a 
sysadmin community.
* PHP: Oh yes. I'm actually somewhat of a php fan, but am finding that in 
the long run Perl is much better at writing reusable and maintainable 
programs. However it's a close call.

Perl's not dead by a long way. I still amaze people how I can solve 
problems in Perl with a few lines of code that would otherwise be either 
impossible, or would take a dedicated C (or whatever) program or would 
take hundreds of lines of VBS. And talking about VBS, more often than not 
the resulting program is unmaintainable and actually does not do the job. 
Or not reliably. Not to say it cannot be done, but the people who can 
write the correct program prefer other languages. And Perl is often one 
of them.

M4
P.S. One of my colleagues refuses to use Perl for his scripts. His 
scripts are KSH only. His reason? Others have to maintain this. I don't 
agree but his scripts are written in such a way even a dumbo can 
understand them. Unlucky us, we have to deal with VOZ ZEK fhccbeg, who do 
not even understand boot up scripts. I can understand his reasons.

P.S.P.S. Same colleague took over some duties from VOZ ZEK fhccbeg, 
because they didn't have the resources for the job at hand. They did 
assign two juniors to look over him. "My god, you did actually write 
those scripts yourself?" Those guys where ready to rename a couple of VGs 
and redistribute the disks in those VGs *by* hand* and thought they could 
do so with reasonable (reasonable here being 100%) accuracy. 


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

Date: 28 Apr 2007 23:39:12 -0700
From: king <hara.acharya@gmail.com>
Subject: Re: use one subroutine's variable value in another subroutine inside a module.
Message-Id: <1177828752.111198.29810@c35g2000hsg.googlegroups.com>

=========================================================================
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;


===========================================================================
injunjoel wrote:
> 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: Sat, 28 Apr 2007 23:24:08 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: UTF8 European characters in MySQL
Message-Id: <q5udnZePlKmSp6nbnZ2dnUVZ_hOdnZ2d@comcast.com>

Alex wrote:
> Jürgen Exner wrote:
> 
>> perldoc utf8:
>>     utf8 - Perl pragma to enable/disable UTF-8 in source code
> 
>> Do you want to use e.g. variable names that are non-ASCII? If yes, then use 
>> utf8 is a good idea.
> 
> Or string literals, yes?
> $string = 'Grüß Gott';

Yes, if your program file is in UTF8 format.  (Simply containing non-ASCII
characters does not automatically mean UTF8).  As shown in "perldoc utf8":

        Enabling the "utf8" pragma has the following effect:

        ·   Bytes in the source text that have their high-bit set will be
            treated as being part of a literal UTF-8 character.  This
            includes most literals such as identifier names, string constants,
            and constant regular expression patterns.

Perl program containing non-ASCII characters in the source code that are
part of the ISO-8859-15 character set and are stored as one byte per
character: don't "use utf8;".

Source code containing non-ASCII characters stored as multiple bytes
per character (by a UFT8-aware editor and/or file system): yes, "use utf8;".

	-Joe


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

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 391
**************************************


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