Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Confusion ,XML::SIMPLE with DATA:DUMPER

by ultibuzz (Monk)
on Nov 20, 2006 at 21:39 UTC ( #585151=note: print w/ replies, xml ) Need Help??


in reply to Confusion ,XML::SIMPLE with DATA:DUMPER

so i used this snipet to fill an array, then i seek in this array untill text is found, then all elements passed so far get the text found behind
well even if this it not the nice way it works

i don't find another way reading the xml::twig documentation
tomorrow i will have again a look, i think its over for today with the brainpower

kd ultibuzz


Comment on Re: Confusion ,XML::SIMPLE with DATA:DUMPER
Re^2: Confusion ,XML::SIMPLE with DATA:DUMPER
by mirod (Canon) on Nov 21, 2006 at 05:14 UTC

    Considering the data you need, there is no way for you to avoid storing the phone numbers, then outputing them when you find the reason. You could leave the elements (and just these elements) in the tree though, by using twig_roots to get the twig built only for them:

    #!/usr/bin/perl use strict; use warnings; use XML::Twig; XML::Twig->new( # the twig will only contain PHONENO/ENTRY and REASON/ +ENTRY elements # (plus the root or it would not be a tree) twig_roots => { 'BL_USER/PHONENO/ENTRY' => 1, + 'BL_DPLI_RECORD/REASON/ENTRY' => \&rea +son, } ) ->parsefile( 'phone_data.xml'); sub reason { my( $t, $reason)= @_; foreach my $phone_no ($reason->prev_siblings) { print $phone_no->text, ";", $reason->text, "\n"; } $t->purge; }

      i have some questions left to understand this.
      with twig_roots it will make me an array if more then 1 entry is presented ?
      $reason->prev_siblings points to that array so the script process it one by one
      what means prev_siblings ?
      kd ultibuzz

        twig_roots doesen't make an array, it makes a tree, with the document root as the root, and the elements listed in the hash as first children. Then the descendants of those elements compose the rest of the tree. prev_siblings means previous siblings. When you get a reason element, at that poit the tree is made of the root, with the phone elements as children, and the reason element as the last child. $reason->prev_siblings will then return the list of phone numbers. Once you're done printing them, you can get rid of them through the purge method, so they don't interfere with the processing of the next set of data.

        Does it make sense?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-04-17 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls