XML::Parser Tree Style - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: XML::Parser Tree Style

Quoted text here. Click to load it

It is an effective way to insert subtle bugs into your code.

   perldoc -q method

      Why can't a method included in this same file be found?
      Make sure to read about creating modules in L<perlmod> and
      the perils of indirect objects in L<perlobj/"Method Invocation">.

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Re: XML::Parser Tree Style

Tad J McClellan wrote:
Quoted text here. Click to load it

Well I guess it depends how well one uses it; I haven't ever had any
problems with it. I personally prefer it, I suppose becasue it's feel
more natural to me, since C/C++ were languages I started programming
with initially (among others, but those mainly.)

Quoted text here. Click to load it



Re: XML::Parser Tree Style

szr schreef:
Quoted text here. Click to load it

Of course you can look at this in that way, but then you would only be
fooling yourself.

Discouraging indirect syntax is a good standard here. Just like
mentioning lexical file handles and three argument opens and the evil of
string eval, over and over again. I wouldn't mind seeing an article with
those points flying by here every week.

Now first check out the "Indirect Object Syntax" section in perlobj.


"indirect object syntax Just Doesn't Work according to a complex series
of rules that almost no one can explain properly"

"The indirect object syntax can break depending on which methods someone
has declared in other namespaces. It's hardly "pathological" to use
namespaces. In my mind, it's silly to hope that those collisions never
occur. They're not easy to debug."

"I see the indirect object syntax as susceptible to breaking due to
action at a distance. When you load a module that otherwise behaves as a
properly-encapsulated black box, it may do things that cause the
indirect object constructor calls to fail."

See also http://markmail.org/message/3g7ujgdkrg7t2sqq

Affijn, Ruud

"Gewoon is een tijger."

Re: XML::Parser Tree Style

Right, notes taken.

I will go away and go through the perlreftutu, perlref and web
examples to figure out refs.
Thanks for all explaining some of the commands.

On Tue, 03 Jun 2008 14:59, Ben Bullock wrote:
Quoted text here. Click to load it

Thanks Ben but when I run this code I get the following:
Attempt to bless into a reference at /usr/lib64/perl5/vendor_perl/
5.8.8/x86_64-linux-thread-multi/XML/Parser.pm line 107.

SO now I need to go and think about array refs.
Just to throw a spanner in the works, I have also been fooling around
with LibXML which was recommended by a perlmonk and it seems very
simple - the immediate advantage is that it allows XPATH style access
and also allows me to write out XML a little more simply.
My question is this:
Ultimatly I wish to parse through my XML document, remove firstname
and lastname, place them in an array (done, we have been through this)
and then remove them out of array, place them into variables which can
be used to construct another document; does LibXML provide perhaps a
simpler mechanism for doing so?

Thanks kindly for all your help, this has proven to be the far most
helpful and warmest help[ group I have found.


 Tad McClellan wrote:
Quoted text here. Click to load it

All well and good Tad but XML::Path is not installed and I have been
told that it will not be installed.

Re: XML::Parser Tree Style

On Wed, 04 Jun 2008 02:19:17 -0700, NiallBCarter wrote:

Quoted text here. Click to load it

You've posted a reply to my message but according to the message it's
a followup to "Dr. Ruud". That might have prevented me from even
seeing your message at all, so I wouldn't have even known about your reply.

Quoted text here. Click to load it

Dunno, sorry. Are you sure you didn't alter anything in the file? Try
copying it out again.

Quoted text here. Click to load it

Here is a thing which unwraps the references from your program (this
runs on my computer)


use strict;
use warnings;

use XML::Parser;
use Data::Dumper;

my $xml=<<EOF;
<?xml version='1.0' encoding='UTF-8'?>
<list name="Nialls list">
my $p = new XML::Parser( Style => 'Tree' );
my $tree = $p->parse($xml);
my $dog = 1;
print ref $dog,"\n";

my $depth = 0;

sub recursively_descend
    my $indent = '   'x$depth;
    my ($thing) = @_;
    if (!ref($thing)) {
    if ($thing =~ /^\s+$/) {
        print "whitespace\n";
    } else {
        print "'$thing'\n";
    } elsif (ref($thing) eq 'ARRAY') {
    print "ARRAY\n";
    my $count = 0;
    for my $k (@) {
        print $indent,"$count:";
        recursively_descend ($k);
    } elsif (ref($thing) eq 'HASH') {
    my @k = keys %;
    if (@k) {
        print "HASH: keys @k\n";
    } else {
        print "HASH: empty\n";
    for my $b (@k) {
        print $indent,"$b:";
        recursively_descend ($$thing);
    } elsif (ref($thing) eq 'SCALAR') {
    print "SCALAR '$$thing'\n";
recursively_descend ($tree);

Quoted text here. Click to load it

You can install it locally in your own account.

Note that since Tad McClellan may not even have seen this, to get a better
response I recommend that you reply to Tad McClellan in a separate
message as a direct followup to him. The Usenet reading software that
most people use is set up so that the threads of conversation are

Re: XML::Parser Tree Style

Quoted text here. Click to load it

If installed your task is completed in 3 lines of code and 10 minutes
of programmer time.

How many hours will it take you without the module?

Are your sysadmins paid many times more than you are?

If not, then it would seem to be bad business to spend money on
reinventing a perfectly good wheel.

Does your manager want to get promoted someday?

Ask him if he prefers spending 10 minutes or 4 hours to get the same thing...

Quoted text here. Click to load it

Then you are done in 10 minutes without annoying the sysadmins
and managers that balk at performing their job function
(providing the resources that their users need).

Quoted text here. Click to load it


I missed seeing that "followup".

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Site Timeline