in reply to Re^3: How to parse this hash? And how to describe my probem?
in thread How to parse this hash? And how to describe my probem?

Aaah! Fixed. Thanks for guinding me...

  • Comment on Re^4: How to parse this hash? And how to describe my probem?

Replies are listed 'Best First'.
Re^5: How to parse this hash? XML question (Twig example)
by Discipulus (Canon) on Jun 08, 2015 at 10:58 UTC
    A quick and dirty approch with XML::Twig (forget xml::simple) and using xml data in Trace On's scratchpad must be a good starting point for your further investigations: each twig's handler is triggered when the specified XPATH is encountered: notice the ugly cur_league workaround..
    #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $cur_league='UNKNOWN'; my $t= XML::Twig->new( twig_handlers => { 'league/id' => sub{ $cur_league = $_[1]->te +xt}, 'event/startDateTime'=>sub{ print "$cur_lea +gue,",$_[1]->text,","; }, 'event/homeTeam/name'=>sub{ print $_[1]->te +xt }, 'event/awayTeam/name'=>sub{ print ",",$_[1] +->text,"\n"; } #add more handlers as needed.. } ); $t->parsefile('trace_on.xml'); __OUTPUT__ 1739,2015-06-24T11:59:00Z,Union Mar del Plata,C. Cordoba Santiago 1739,2015-06-08T20:59:00Z,Douglas Haig,Santamarina Tandil 1740,2015-06-30T16:59:00Z,Arsenal de Sarandi,Crucero del Norte 1740,2015-06-14T11:59:00Z,Aldosivi Mar del Plata,Rosario Central 1740,2015-06-14T11:59:00Z,Arsenal de Sarandi,Gimnasia La Plata 1740,2015-06-14T11:59:00Z,Atletico Huracan,Defensa y Justicia 1740,2015-06-14T11:59:00Z,Belgrano de Cordoba,Argentinos Juniors 1740,2015-06-14T11:59:00Z,Estudiantes La Plata,San Martin San Juan 1740,2015-06-14T11:59:00Z,Godoy Cruz Antonio Tomba,Crucero del Norte 1740,2015-06-14T11:59:00Z,Independiente,Olimpo Bahia Blanca 1740,2015-06-14T11:59:00Z,Lanus,Atletico Rafaela 1740,2015-06-14T11:59:00Z,Newells Old Boys,Racing Club 1740,2015-06-14T11:59:00Z,Nueva Chicago BA,Colon de Santa Fe 1740,2015-06-14T11:59:00Z,Quilmes,Banfield 1740,2015-06-14T11:59:00Z,River Plate,Temperley 1740,2015-06-14T11:59:00Z,Sarmiento,Boca Juniors 1740,2015-06-14T11:59:00Z,Union Santa Fe,San Lorenzo 1740,2015-06-14T11:59:00Z,Velez Sarsfield,Club Atletico Tigre 1740,2015-06-08T20:59:00Z,Club Atletico Tigre,Aldosivi Mar del Plata 1740,2015-06-08T23:09:00Z,Defensa y Justicia,Estudiantes La Plata 1756,2015-06-08T10:29:00Z,Bulleen Lions,Brunswick City


    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Thank you! That helped a lot. I spent quite some time to do some basic research on XML Twig and XML.

      But I still do not understand how your workaround works. It is cool that you get the league-number for every line. I would like to have something like that for all the 'spreads' as well. But that seems to involve some kind of recursion. And my little brain is to small for that. I have tried to understand this tutorial. But I am not all the way trough...

      pad://http://www.xml.com/lpt/a/750

        If you add  warn $_->path, "\n"; to every callback you can observe a magical hint

        Then try something  'spreads/spread' => sub { ... } ... http://xmltwig.org/tutorial/