[30674] in Perl-Users-Digest
Perl-Users Digest, Issue: 1919 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 13 09:09:48 2008
Date: Mon, 13 Oct 2008 06:09:12 -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 Mon, 13 Oct 2008 Volume: 11 Number: 1919
Today's topics:
Re: FAQ 4.24 How do I reverse a string? <whynot@pozharski.name>
Re: GETDATA to POSTDATA <smallpond@juno.com>
How does mod_perl module caching work? <tszming@gmail.com>
Re: How does mod_perl module caching work? <joost@zeekat.nl>
Re: How does mod_perl module caching work? <peter@makholm.net>
new CPAN modules on Mon Oct 13 2008 (Randal Schwartz)
Odd behaviour with has key - wide character <jcombe@gmail.com>
Re: Odd behaviour with has key - wide character <RedGrittyBrick@spamweary.invalid>
Re: Odd behaviour with has key - wide character <RedGrittyBrick@spamweary.invalid>
Re: Odd behaviour with has key - wide character <peter@makholm.net>
Re: Odd behaviour with has key - wide character <joost@zeekat.nl>
Problem using ';' in an INI file and parsing <cokeeffe@gmail.com>
Problem with perlsax splitting the calls to characters <rsasanka@gmail.com>
Re: Problem with perlsax splitting the calls to charact <RedGrittyBrick@spamweary.invalid>
Re: Problem with perlsax splitting the calls to charact <rsasanka@gmail.com>
Re: Want true instantiated objects from XML <zed@resonant.org>
Re: Want true instantiated objects from XML sln@netherlands.com
Re: Want true instantiated objects from XML <newsbot@cox.net>
Re: Want true instantiated objects from XML <newsbot@cox.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Oct 2008 23:50:10 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <slrngf4oo1.rlu.whynot@orphan.zombinet>
On 2008-10-12, Jürgen Exner <jurgenex@hotmail.com> wrote:
*SKIP*
>>It's not been obvious to most people I teach. Most people only see it
>>as a list operator.
>>> Therefore I suggest removing it.
>>It's not hurting anyone where it is.
> It is cluttering the FAQ, therefore I suggested removing it /if/ it
> doesn't provide any useful information. However apparently there are
> indeed people to whom it is useful. Do others share Brian's
> experience/sentiment?
Me counts? I can't comment on "experience", but "sentiment" is OK
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Sun, 12 Oct 2008 20:16:46 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: GETDATA to POSTDATA
Message-Id: <875ed711-d0b2-4bed-999b-236e765dc65c@v28g2000hsv.googlegroups.com>
On Oct 11, 12:28 pm, "Daniel Kaplan" <NoS...@NoSpam.com> wrote:
> Hi,
>
> I have a page that the server redirects to incase of an SQL Inject attempt.
> The thing is, because of the rewrite rule (something beyond my
> understanding) the page won't work properly. Call it directly, it works,
> call it via the rule, not so much.
>
> What does work is if in that new page, I redirect it to another copy of that
> page, and then it works.
>
> But here is my problem:
>
> I cannot redirect it with the same URL because that triggers the redirect
> rule (again, written in the server OS), and therefore my Perl redirect just
> loops.
>
> So my question is:
>
> Can I take that URL I have, and somehow pass it to my copy with the data in
> the URL now in POSTDATA format? Because POSTDATA won't trigger the redirect
> rule.
>
> Many thanks ahead, as always.
How can I use X to do Y?
http://www.catb.org/~esr/faqs/smart-questions.html#id307781
------------------------------
Date: Mon, 13 Oct 2008 02:45:47 -0700 (PDT)
From: tszming <tszming@gmail.com>
Subject: How does mod_perl module caching work?
Message-Id: <a74fe379-c622-4d9b-b3dc-5869a8613839@b30g2000prf.googlegroups.com>
Hello,
I have complied my apache (1.3.41) to use mod_perl, and in the
httpd.conf I added the following:
<Location /cgi-bin/>
PerlModule Apache::DBI
SetHandler perl-script
PerlHandler Apache::Registry
Options ExecCGI
allow from all
PerlSendHeader On
</Location>
I was able to run the perl script, but seems mod_perl never cache my
modules?
E.g.
TestModPerl.pm
==============================
use strict;
package TestModPerl;
sub new {
my ($class) = @_;
my $self = {
name => "foo"
};
bless $self, $class;
return $self;
}
1;
test.cgi
==============================
#!/usr/bin/perl
use lib "./../lib/";
use TestModPerl;
print "Content-type:text/html\n\n";
$t = new TestModPerl();
print $t->{"name"};
-------------------------------
After started Apache, even if I modify the TestModPerl.pm by editing
the name, the change is done realtime.
So how does mod_perl module caching work?
Best Regard,
Howa
------------------------------
Date: Mon, 13 Oct 2008 12:00:49 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: How does mod_perl module caching work?
Message-Id: <87vdvwak6m.fsf@zeekat.nl>
tszming <tszming@gmail.com> writes:
> Hello,
>
> I have complied my apache (1.3.41) to use mod_perl, and in the
> httpd.conf I added the following:
>
> <Location /cgi-bin/>
> PerlModule Apache::DBI
> SetHandler perl-script
> PerlHandler Apache::Registry
> Options ExecCGI
> allow from all
> PerlSendHeader On
> </Location>
>
> I was able to run the perl script, but seems mod_perl never cache my
> modules?
If you use the PerlModule directive inside a conditional directive (like
<Location>), it will load the module the first time that location is
visited, by which time you've usually got more than one apache child
process running. That means when you reload the page, chances are fairly
good you've got another child process and the module will get loaded
again for that child. The same thing applies to the scripts in the
/cgi-bin/ directory.
http://perl.apache.org/docs/1.0/guide/performance.html#Preloading_Perl_Modules_at_Server_Startup
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Mon, 13 Oct 2008 12:10:07 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: How does mod_perl module caching work?
Message-Id: <8763nwu7pc.fsf@hacking.dk>
tszming <tszming@gmail.com> writes:
> After started Apache, even if I modify the TestModPerl.pm by editing
> the name, the change is done realtime.
Apache::Registry checks the caches the mtime of the script and
recompiles the script if the mtime changes. This way everything works
as expected for cgi-scripts unless you're doing unusable things.
//Makholm
------------------------------
Date: Mon, 13 Oct 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Oct 13 2008
Message-Id: <K8nuEM.JMz@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.
API-PleskExpand-1.07
http://search.cpan.org/~nrg/API-PleskExpand-1.07/
OOP interface to the Plesk Expand XML API (http://www.parallels.com/en/products/plesk/expand/).
----
Apache2-AuthHatena-0.05
http://search.cpan.org/~danjou/Apache2-AuthHatena-0.05/
Simple authentication mod_perl module using Hatena Auth API
----
Apache2-AuthzHatenaPoint-0.02
http://search.cpan.org/~danjou/Apache2-AuthzHatenaPoint-0.02/
a module to authorize http clients with hatena point.
----
App-ZofCMS-Plugin-BreadCrumbs-0.0102
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-BreadCrumbs-0.0102/
add "breadcrumbs" navigation to your sites
----
App-ZofCMS-Plugin-UserLogin-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-UserLogin-0.0101/
restrict access to pages based on user accounts
----
Archive-Zip-1.26
http://search.cpan.org/~adamk/Archive-Zip-1.26/
Provide an interface to ZIP archive files.
----
Authen-Htpasswd-0.161
http://search.cpan.org/~dkamholz/Authen-Htpasswd-0.161/
interface to read and modify Apache .htpasswd files
----
CPAN-1.93
http://search.cpan.org/~andk/CPAN-1.93/
query, download and build perl modules from CPAN sites
----
Class-DBI-Lite-0.013
http://search.cpan.org/~johnd/Class-DBI-Lite-0.013/
Lightweight ORM for Perl
----
DataExtract-FixedWidth-0.08
http://search.cpan.org/~ecarroll/DataExtract-FixedWidth-0.08/
The one stop shop for parsing static column width text tables!
----
DataExtract-FixedWidth-0.09
http://search.cpan.org/~ecarroll/DataExtract-FixedWidth-0.09/
The one stop shop for parsing static column width text tables!
----
Devel-PPPort-3.14_02
http://search.cpan.org/~mhx/Devel-PPPort-3.14_02/
Perl/Pollution/Portability
----
Encode-Arabic-1.8
http://search.cpan.org/~smrz/Encode-Arabic-1.8/
Encodings of Arabic
----
ExtUtils-Command-1.15
http://search.cpan.org/~rkobes/ExtUtils-Command-1.15/
utilities to replace common UNIX commands in Makefiles etc.
----
ExtUtils-Manifest-1.55
http://search.cpan.org/~rkobes/ExtUtils-Manifest-1.55/
utilities to write and check a MANIFEST file
----
Ezmlm-0.08.1
http://search.cpan.org/~sumpfrall/Ezmlm-0.08.1/
Object Methods for Ezmlm Mailing Lists
----
Games-Sudoku-SudokuTk-0.12
http://search.cpan.org/~cguine/Games-Sudoku-SudokuTk-0.12/
Sudoku Game
----
IO-AIO-3.15
http://search.cpan.org/~mlehmann/IO-AIO-3.15/
Asynchronous Input/Output
----
IPDR-Collection-0.06
http://search.cpan.org/~shamrock/IPDR-Collection-0.06/
----
MIKER-CPAN-ForceSmokerTest-0.002
http://search.cpan.org/~miker/MIKER-CPAN-ForceSmokerTest-0.002/
Stuff to run through CPAN smokers
----
Math-GSL-0.13_02
http://search.cpan.org/~leto/Math-GSL-0.13_02/
Perl interface to the GNU Scientific Library (GSL)
----
Memoize-Memcached-0.01
http://search.cpan.org/~dtrischuk/Memoize-Memcached-0.01/
use a memcached cache to memoize functions
----
Memoize-Memcached-0.02
http://search.cpan.org/~dtrischuk/Memoize-Memcached-0.02/
use a memcached cache to memoize functions
----
Module-Install-DBICx-AutoDoc-0.01_01
http://search.cpan.org/~jmmills/Module-Install-DBICx-AutoDoc-0.01_01/
Use your make file to run DBICx::AutoDoc
----
Net-IMAP-Simple-Plus-1.17002
http://search.cpan.org/~jettero/Net-IMAP-Simple-Plus-1.17002/
NIS 1.71 plus a couple patches
----
Net-NBsocket-0.14
http://search.cpan.org/~miker/Net-NBsocket-0.14/
Non-Blocking Sockets
----
POE-Component-IRC-Plugin-WWW-GetPageTitle-0.0101
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-WWW-GetPageTitle-0.0101/
web page title fetching IRC plugin
----
POE-Component-IRC-Plugin-WWW-Google-Time-0.0101
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-WWW-Google-Time-0.0101/
access time data from Google via IRC
----
POE-Component-WWW-DoctypeGrabber-0.0101
http://search.cpan.org/~zoffix/POE-Component-WWW-DoctypeGrabber-0.0101/
non-blocking wrapper around WWW::DoctypeGrabber
----
POE-Component-WWW-GetPageTitle-0.0101
http://search.cpan.org/~zoffix/POE-Component-WWW-GetPageTitle-0.0101/
non-blocking wrapper around WWW::GetPageTitle
----
POE-Component-WWW-Google-Time-0.0101
http://search.cpan.org/~zoffix/POE-Component-WWW-Google-Time-0.0101/
non-blocking wrapper around WWW::Google::Time
----
Pg-Loader-0.09
http://search.cpan.org/~ioannis/Pg-Loader-0.09/
Perl extension for loading Postgres tables
----
Pod-Eventual-0.003
http://search.cpan.org/~rjbs/Pod-Eventual-0.003/
read a POD document as a series of trivial events
----
Pod-Weaver-1.000
http://search.cpan.org/~rjbs/Pod-Weaver-1.000/
do horrible things to POD, producing better docs
----
Pod-Weaver-1.001
http://search.cpan.org/~rjbs/Pod-Weaver-1.001/
do horrible things to POD, producing better docs
----
Remote-Use-0.04
http://search.cpan.org/~casiano/Remote-Use-0.04/
Using modules from a remote server
----
SVN-Dumpfile-0.13.101
http://search.cpan.org/~mscharrer/SVN-Dumpfile-0.13.101/
Perl extension to access and manipulate Subversion dumpfiles
----
Task-App-ZofCMS-0.0101
http://search.cpan.org/~zoffix/Task-App-ZofCMS-0.0101/
bundle of ZofCMS core and all of its plugins
----
Test-WWW-Declare-0.02
http://search.cpan.org/~sartak/Test-WWW-Declare-0.02/
declarative testing for your web app
----
Text-Template-Simple-0.62_05
http://search.cpan.org/~burak/Text-Template-Simple-0.62_05/
Simple text template engine
----
Variable-Magic-0.24
http://search.cpan.org/~vpit/Variable-Magic-0.24/
Associate user-defined magic to variables from Perl.
----
WWW-GetPageTitle-0.0101
http://search.cpan.org/~zoffix/WWW-GetPageTitle-0.0101/
get titles of web pages
----
WWW-GetPageTitle-0.0102
http://search.cpan.org/~zoffix/WWW-GetPageTitle-0.0102/
get titles of web pages
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/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Mon, 13 Oct 2008 05:34:27 -0700 (PDT)
From: Jon Combe <jcombe@gmail.com>
Subject: Odd behaviour with has key - wide character
Message-Id: <003835d6-c3f6-4415-9dce-761882c2ac4b@k30g2000hse.googlegroups.com>
Does the letter "v" have any significance when creating a hash key?
The following code snippet does not behave as I expect it to:-
#!/usr/bin/perl -w
%H =3D (v365, 3);
print keys %H;
When run it outputs
Wide character in print at wide.pl line 4.
=C5=AD
When the key name is changed to "va365" it prints "va365" as I expect.
What is special about just v followed by numbers?
Jon.
------------------------------
Date: Mon, 13 Oct 2008 13:40:48 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <48f341d5$0$29497$da0feed9@news.zen.co.uk>
Jon Combe wrote:
> Does the letter "v" have any significance when creating a hash key?
> The following code snippet does not behave as I expect it to:-
>
> #!/usr/bin/perl -w
>
> %H = (v365, 3);
> print keys %H;
>
> When run it outputs
>
> Wide character in print at wide.pl line 4.
> ŭ
>
> When the key name is changed to "va365" it prints "va365" as I expect.
> What is special about just v followed by numbers?
>
Have you tried it with "use strict;"?
--
RGB
------------------------------
Date: Mon, 13 Oct 2008 13:43:34 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <48f3427b$0$29497$da0feed9@news.zen.co.uk>
RedGrittyBrick wrote:
>
> Jon Combe wrote:
>> Does the letter "v" have any significance when creating a hash key?
>> The following code snippet does not behave as I expect it to:-
>>
>> #!/usr/bin/perl -w
>>
>> %H = (v365, 3);
>> print keys %H;
>>
>> When run it outputs
>>
>> Wide character in print at wide.pl line 4.
>> Å
>>
>> When the key name is changed to "va365" it prints "va365" as I expect.
>> What is special about just v followed by numbers?
>>
>
> Have you tried it with "use strict;"?
>
>
Have *I*? (oops)
C:\>perl -Mstrict -e "my %H=(v365,3); print keys %H"
Wide character in print at -e line 1.
ŭ
C:\>perl -Mstrict -e "my %H=('v365',3); print keys %H"
v365
Somehow I thought strict would catch that. :-(
--
RGB
------------------------------
Date: Mon, 13 Oct 2008 14:53:32 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <87skr0slkj.fsf@hacking.dk>
Jon Combe <jcombe@gmail.com> writes:
> The following code snippet does not behave as I expect it to:-
>
> #!/usr/bin/perl -w
>
> %H = (v365, 3);
> print keys %H;
No, it isn't the usage as a hash key that makes the v special. In
general a bareword consisting of a v followed by some numbers
seperated by dots is handled like this.
Look it up in 'perldoc perldata' under the heading 'Version Strings'.
If it was a normal string, 'use strict' would have warned you about
the bareword not being allowed. But it really isn't a bareword because
of the v-string handling.
//Makholm
------------------------------
Date: Mon, 13 Oct 2008 14:55:00 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Odd behaviour with has key - wide character
Message-Id: <87ljwsac4b.fsf@zeekat.nl>
Jon Combe <jcombe@gmail.com> writes:
> Does the letter "v" have any significance when creating a hash key?
> The following code snippet does not behave as I expect it to:-
>
> #!/usr/bin/perl -w
>
> %H = (v365, 3);
> print keys %H;
you're running into version string. Since 5.8, perl handles
vX.Y.Z... where X Y and Z are numbers specially (this is considered a
failed experiment by many people).
note that any other letter would have caused an error under "strict":
use strict;
%h = ( b123, 3);
Global symbol "%h" requires explicit package name at - line 2.
Bareword "b123" not allowed while "strict subs" in use at - line 2.
Execution of - aborted due to compilation errors.
you should either manually quote the keys of a hash, or use the
auto-quoting => operator:
use strict;
my %h = ( v123 => 3 );
Note that even using => will not work correctly at 5.8.0: you should
really upgrade your perl if you've got that version, since it has lots
of bugs.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Mon, 13 Oct 2008 03:30:14 -0700 (PDT)
From: "Colin O'Keeffe" <cokeeffe@gmail.com>
Subject: Problem using ';' in an INI file and parsing
Message-Id: <578a4056-770b-43cf-bcd1-a682634a7980@2g2000hsn.googlegroups.com>
Hi,
I'm using Config::Abstract::Ini to parse an INI file im using to store
configuration information. The problem is in my INI file one of the
entries is a BASH command like so
command1 = "cat myfile.txt | while read LINE ; do awk -F ',' '{print
$5}' ; done"
Now when it's parsed, it only comes out as
cat myfile.txt | while read LINE
as there's the ; in the command. is there any way to get the parser to
ignore this? can a hex or decimal representation be used in the bash
command?
thanks
------------------------------
Date: Mon, 13 Oct 2008 03:17:18 -0700 (PDT)
From: raga <rsasanka@gmail.com>
Subject: Problem with perlsax splitting the calls to characters callback
Message-Id: <95a2ccc9-c2d9-4d13-9289-a3e6ecd15fef@k13g2000hse.googlegroups.com>
From the link given here :
http://search.cpan.org/~kmacleod/libxml-perl-0.08/doc/PerlSAX.pod
Perl sax seems to split the characters call for a single entity.
Though this is wierd.(not sure if there is a genuine reason) it is
fine.. as all belong to same entity, we can simply append all the
characters calls.
However ,sadly it just calls the characters api with an unwanted
space.
Eg: i've tag < tag1>mynameisrs</tag>
it calls characters("myname") characters(" ") characters("isrs") ,
It is not atall predictible why it is doing this way. coz the problem
is when i append it becomes "myname isrs".
Any help is appreciated.
Thanks
------------------------------
Date: Mon, 13 Oct 2008 13:06:44 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Problem with perlsax splitting the calls to characters callback
Message-Id: <48f339d9$0$29508$da0feed9@news.zen.co.uk>
raga wrote:
> From the link given here :
> http://search.cpan.org/~kmacleod/libxml-perl-0.08/doc/PerlSAX.pod
> Perl sax seems to split the characters call for a single entity.
> Though this is wierd.(not sure if there is a genuine reason) it is
> fine.. as all belong to same entity, we can simply append all the
> characters calls.
The URL you provide says this:
"The Parser will call this method to report each chunk of character
data. SAX parsers may return all contiguous character data in a single
chunk, or they may split it into several chunks;"
> However ,sadly it just calls the characters api with an unwanted
> space.
> Eg: i've tag < tag1>mynameisrs</tag>
That isn't well formed XML and so cant be parsed.
1. you have a space in front of the firts tag name.
2. you open tag1 but close tag.
> it calls characters("myname") characters(" ") characters("isrs") ,
> It is not atall predictible why it is doing this way.
In my experience it is always sufficiently predictable. Probably your
mynameisrs data is split over several lines and you've not written your
handler to take this into account.
$ cat sax.pl
#!/usr/local/bin/perl
use strict;
use warnings;
use XML::Parser::PerlSAX;
my $xml="<tag>mynameisrs</tag>";
my $handler = MyHandler->new();
my $parser = XML::Parser::PerlSAX->new(Handler=>$handler);
$parser->parse($xml);
package MyHandler;
use strict;
use warnings;
use Data::Dumper;
sub new {
my $type = shift;
return bless {}, $type;
}
my $current_element = '';
sub start_element {
my ($self, $element) = @_;
$current_element = $element->{Name};
print "Start: <$current_element>\n";
}
sub end_element {
my ($self, $element) = @_;
print "End: \n";
}
sub characters {
my ($self, $characters) = @_;
my $text = $characters->{Data};
print "Characters: '$text'\n";
}
1;
$ perl sax.pl
Start: <tag>
Characters: 'mynameisrs'
End:
--
RGB
------------------------------
Date: Mon, 13 Oct 2008 05:45:53 -0700 (PDT)
From: raga <rsasanka@gmail.com>
Subject: Re: Problem with perlsax splitting the calls to characters callback
Message-Id: <b73735c5-00fd-4f99-80b2-52b01d09dd53@p58g2000hsb.googlegroups.com>
On Oct 13, 5:06=A0pm, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
wrote:
> raga wrote:
> > From the link given here :
> >http://search.cpan.org/~kmacleod/libxml-perl-0.08/doc/PerlSAX.pod
> > Perl sax seems to split the characters call for a single entity.
> > Though this is wierd.(not sure if there is a genuine reason) =A0it is
> > fine.. as all belong to same entity, we can simply append all the
> > characters calls.
>
> The URL you provide says this:
>
> "The Parser will call this method to report each chunk of character
> data. SAX parsers may return all contiguous character data in a single
> chunk, or they may split it into several chunks;"
>
> > However ,sadly it just calls the characters api with an unwanted
> > space.
> > Eg: i've tag < tag1>mynameisrs</tag>
>
> That isn't well formed XML and so cant be parsed.
> 1. you have a space in front of the firts tag name.
> 2. you open tag1 but close tag.
>
> > it calls characters("myname") characters(" ") characters("isrs") ,
> > It is not atall predictible why it is doing this way.
>
> In my experience it is always sufficiently predictable. Probably your
> mynameisrs data is split over several lines and you've not written your
> handler to take this into account.
>
> $ cat sax.pl
> #!/usr/local/bin/perl
> use strict;
> use warnings;
> use XML::Parser::PerlSAX;
>
> my $xml=3D"<tag>mynameisrs</tag>";
>
> my $handler =3D MyHandler->new();
> my $parser =3D XML::Parser::PerlSAX->new(Handler=3D>$handler);
>
> $parser->parse($xml);
>
> package MyHandler;
> use strict;
> use warnings;
> use Data::Dumper;
>
> sub new {
> =A0 =A0my $type =3D shift;
> =A0 =A0return bless {}, $type;
>
> }
>
> my $current_element =3D '';
>
> sub start_element {
> =A0 =A0 =A0my ($self, $element) =3D @_;
> =A0 =A0 =A0$current_element =3D $element->{Name};
> =A0 =A0 =A0print "Start: <$current_element>\n";
>
> }
>
> sub end_element {
> =A0 =A0 =A0my ($self, $element) =3D @_;
> =A0 =A0 =A0print "End: \n";
>
> }
>
> sub characters {
> =A0 =A0 =A0my ($self, $characters) =3D @_;
> =A0 =A0 =A0my $text =3D $characters->{Data};
> =A0 =A0 =A0print "Characters: '$text'\n";
>
> }
>
> 1;
>
> $ perl sax.pl
> Start: <tag>
> Characters: 'mynameisrs'
> End:
>
> --
> RGB
sorry for the wrong input provided earlier.. it was my hurry to type
quickly
i intended to type <tag>mynameisrs</tag>
Yes, the perlsax occasionally splits the chars to multiple calls. ur
snip doesnt seems to handle it!.
My actual query is in addition to the calls made to the charchters api
with the split chunks, it randomly calls the characters API with a
unwanted space..
Thanks again for ur earlier reply.
------------------------------
Date: Sun, 12 Oct 2008 23:17:01 GMT
From: Zed Pobre <zed@resonant.org>
Subject: Re: Want true instantiated objects from XML
Message-Id: <slrngf4tsb.vq1.zed@resonant.org>
/usr/ceo <newsbot@cox.net> wrote:
> I've looked through SOAP::Lite (and SOAP::Serialize and
> SOAP::Deserialize). I'm a fairly frequent user of XML::Simple, but
> Simple doesn't do the above (AFAIK). SURELY *something* like this is
> "out there" (read "CPAN") but I can't seem to find it; only things
> close to it (like SOAP::SOM objects that require an xpath of sorts and
> my methods are still not available through an instantiated method of
> just the data [object attributes] in XML.)
I would do it with XML::Twig, myself, though there are other options.
#!/usr/bin/perl
use strict; use warnings
use Person;
use XML::Twig;
my $twig = XML::Twig->new();
$twig->parse(\*DATA);
my ($name, $age);
my $person;
my @personslist;
my @xmlpersons = $twig->root->descendants('Persons');
foreach my $element (@xmlpersons)
{
$name = $element->att('name');
$age = $element->att('age');
$person = Person->new('name' => $name, 'age' => $age);
push(@personslist,$person);
}
__DATA__
<xml>
<People>
<Person name="John Doe" age="22" />
<Person name="Jane Doe" age="23" />
<Person name="Maxx Doogan" age="10" />
</People>
</xml>
##########
You're looking for something like that?
--
Zed Pobre <zed@resonant.org> a.k.a. Zed Pobre <zed@debian.org>
PGP key and fingerprint available on finger; encrypted mail welcomed.
------------------------------
Date: Sun, 12 Oct 2008 23:46:04 GMT
From: sln@netherlands.com
Subject: Re: Want true instantiated objects from XML
Message-Id: <os25f41c79noj8l6pniterdpk5f2bigmp5@4ax.com>
On Sun, 12 Oct 2008 14:01:14 -0700 (PDT), "/usr/ceo" <newsbot@cox.net> wrote:
>I've had a need for this at points in the past, but was always able to
>code around it (and still could even now), but I'd really like to be
>able to do this, and I can't find anything out there that does this
>exactly as I want. (Which tends to make me believe what I want
>wouldn't be as immediately useful as maybe I would think it to be,
>but...?!)
>
>Given an object defined as this:
>
>package Person;
>
>use strict;
>use warnings qw( all );
>
>sub new {
> my $proto = shift;
> my $class = ref $proto || $proto;
> my %attrs = @_;
> my $self = {};
>
> # Nevermind the error checking for attributes right now.
>
> $self->{__name} = $attrs{name};
> $self->{__age} = $attrs{age};
>
> bless $class, $self;
>
> return $self;
>}
>
># RW attributes.
>
>sub name { $s = shift; $s->{__name} = shift if @_; return $s-
>>{__name} }
>sub age { $s = shift; $s->{__age} = shift if @_; return $s->{__age} }
>
># Methods.
>
>sub sayName { print "My name is: " . shift->{__name} . "\n" }
>sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
>
>1;
>
The above is all very impressive. What do you want to do?
>I want to be able to read the following XML and create instances of
>Person from each instance in the XML:
>
><xml>
><People>
> <Person name="John Doe" age="22" />
> <Person name="Jane Doe" age="23" />
> <Person name="Maxx Doogan" age="10" />
></People>
></xml>
>
So XML parsing is holding you up?
>So I get an array of Person objects which I can then write:
>
>my @people; # Hold the array of Person object created from the XML
>above.
>
>for my $person (@people) {
> $person->sayName();
> $person->sayAge();
>}
>
>I've looked through SOAP::Lite (and SOAP::Serialize and
>SOAP::Deserialize). I'm a fairly frequent user of XML::Simple, but
>Simple doesn't do the above (AFAIK). SURELY *something* like this is
>"out there" (read "CPAN") but I can't seem to find it; only things
>close to it (like SOAP::SOM objects that require an xpath of sorts and
>my methods are still not available through an instantiated method of
>just the data [object attributes] in XML.)
>
>Thanks!
>/usr/ceo
rxparse version 2
sln
------------------------------
Date: Sun, 12 Oct 2008 23:53:57 -0700 (PDT)
From: "/usr/ceo" <newsbot@cox.net>
Subject: Re: Want true instantiated objects from XML
Message-Id: <7d5b89f5-b7da-47cf-8a21-bd8f9c2348c8@j22g2000hsf.googlegroups.com>
On Oct 12, 6:17=A0pm, Zed Pobre <z...@resonant.org> wrote:
> /usr/ceo <news...@cox.net> wrote:
> > I've looked through SOAP::Lite (and SOAP::Serialize and
> > SOAP::Deserialize). =A0I'm a fairly frequent user of XML::Simple, but
> > Simple doesn't do the above (AFAIK). =A0SURELY *something* like this is
> > "out there" (read "CPAN") but I can't seem to find it; only things
> > close to it (like SOAP::SOM objects that require an xpath of sorts and
> > my methods are still not available through an instantiated method of
> > just the data [object attributes] in XML.)
>
> I would do it with XML::Twig, myself, though there are other options.
>
> #!/usr/bin/perl
> use strict; use warnings
> use Person;
> use XML::Twig;
>
> my $twig =3D XML::Twig->new();
> $twig->parse(\*DATA);
>
> my ($name, $age);
> my $person;
> my @personslist;
> my @xmlpersons =3D $twig->root->descendants('Persons');
>
> foreach my $element (@xmlpersons)
> {
> =A0 =A0 $name =3D $element->att('name');
> =A0 =A0 $age =3D $element->att('age');
> =A0 =A0 $person =3D Person->new('name' =3D> $name, 'age' =3D> $age);
> =A0 =A0 push(@personslist,$person);
>
> }
>
> __DATA__
> <xml>
> <People>
> =A0 =A0 <Person name=3D"John Doe" age=3D"22" />
> =A0 =A0 <Person name=3D"Jane Doe" age=3D"23" />
> =A0 =A0 <Person name=3D"Maxx Doogan" age=3D"10" />
> </People>
> </xml>
>
> ##########
>
> You're looking for something like that?
Well that's definitely pretty nice. It's about halfway between what I
want and what I thought I was going to have to do, which was close to
what you wrote -- I just hadn't looked at XML::Twig. This is close
enough to what I want without providing a schema upfront (which is why
I think it would be a little difficult to write something smart enough
to marshall to and from XML since XML is for all intents and purposes,
free-format.)
I think the XML::Twig hit will be helpful and I'll probably do that.
Thanks!
/usr/ceo
------------------------------
Date: Sun, 12 Oct 2008 23:57:14 -0700 (PDT)
From: "/usr/ceo" <newsbot@cox.net>
Subject: Re: Want true instantiated objects from XML
Message-Id: <64f1b9dc-8d59-4bce-82d3-dd66afeb263c@v56g2000hsf.googlegroups.com>
On Oct 12, 6:46=A0pm, s...@netherlands.com wrote:
> On Sun, 12 Oct 2008 14:01:14 -0700 (PDT), "/usr/ceo" <news...@cox.net> wr=
ote:
> >I've had a need for this at points in the past, but was always able to
> >code around it (and still could even now), but I'd really like to be
> >able to do this, and I can't find anything out there that does this
> >exactly as I want. =A0(Which tends to make me believe what I want
> >wouldn't be as immediately useful as maybe I would think it to be,
> >but...?!)
>
> >Given an object defined as this:
>
> >package Person;
>
> >use strict;
> >use warnings qw( all );
>
> >sub new {
> > =A0 my $proto =3D shift;
> > =A0 my $class =3D ref $proto || $proto;
> > =A0 my %attrs =3D @_;
> > =A0 my $self =3D {};
>
> > =A0 # Nevermind the error checking for attributes right now.
>
> > =A0 $self->{__name} =3D $attrs{name};
> > =A0 $self->{__age} =3D $attrs{age};
>
> > =A0 bless $class, $self;
>
> > =A0 return $self;
> >}
>
> ># RW attributes.
>
> >sub name { $s =3D shift; $s->{__name} =3D shift if @_; return $s-
> >>{__name} }
> >sub age { $s =3D shift; $s->{__age} =3D shift if @_; return $s->{__age} =
}
>
> ># Methods.
>
> >sub sayName { print "My name is: " . shift->{__name} . "\n" }
> >sub sayAge { print "I am " . shift->{__age} . " years old.\n" }
>
> >1;
>
> The above is all very impressive. What do you want to do?
>
> >I want to be able to read the following XML and create instances of
> >Person from each instance in the XML:
>
> ><xml>
> ><People>
> > =A0 <Person name=3D"John Doe" age=3D"22" />
> > =A0 <Person name=3D"Jane Doe" age=3D"23" />
> > =A0 <Person name=3D"Maxx Doogan" age=3D"10" />
> ></People>
> ></xml>
>
> So XML parsing is holding you up?
No, I can parse most of the XML I need with XML::Simple. The point
is, I don't really want the hashed structure that XML::Simple
provides, even though I can munge the parsing with ForceGroup and
other options. So no, the parsing isn't the issue. I want more of an
XML "freeze / unfreeze" or serialize / deserialize (marshalling)
solution. (Marshalling and s/d aren't always the same I realize...)
>
>
> >So I get an array of Person objects which I can then write:
>
> >my @people; # Hold the array of Person object created from the XML
> >above.
>
> >for my $person (@people) {
> > =A0 $person->sayName();
> > =A0 $person->sayAge();
> >}
>
> >I've looked through SOAP::Lite (and SOAP::Serialize and
> >SOAP::Deserialize). =A0I'm a fairly frequent user of XML::Simple, but
> >Simple doesn't do the above (AFAIK). =A0SURELY *something* like this is
> >"out there" (read "CPAN") but I can't seem to find it; only things
> >close to it (like SOAP::SOM objects that require an xpath of sorts and
> >my methods are still not available through an instantiated method of
> >just the data [object attributes] in XML.)
>
> >Thanks!
> >/usr/ceo
>
> rxparse version 2
I'll check that out as well, but the solution Zed offered was closer
to what I was looking for. Close enough.
Thanks!
/usr/ceo
------------------------------
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 1919
***************************************