in reply to Re^7: How to parse this hash? XML question (Twig example)
in thread How to parse this hash? And how to describe my probem?

Hm. Ok. I am a step further. But why don't I get the right values with this:

my $t= XML::Twig->new( twig_handlers => { 'league/id' =>sub +{ $leagueId = $_[1]->text;}, 'event/startDateTime' + =>sub{ $date = $_[1]->text;}, 'event/homeTeam/name' + =>sub{ $home = $_[1]->text;}, 'event/awayTeam/name' + =>sub{ $away = $_[1]->text;}, 'event/periods/period/number' + =>sub{ $period = $_[1]->text;}, 'event/periods/period/description' + =>sub{ $perDescr = $_[1]->text;}, 'event/periods/period/maxBetAmount/moneyLine +' =>sub{ $maxBetML = $_[1]->text;}, 'event/periods/period/moneyLine/homePrice' + =>sub{ $homePrice = $_[1]->text;}, 'event/periods/period/moneyLine/drawPrice' + =>sub{ $drawPrice = $_[1]->text;}, 'event/periods/period/moneyLine/awayPrice' + =>sub{ $awayPrice = $_[1]->text; print "\nMoney,", $lea +gueId, " ", $date, " ", $home, " ", $away, " ", $period, +" ", $perDescr, " ", $maxBetML, " ", $homePrice, " ", $dr +awPrice, " ", $awayPrice; } );

Your code gives me all fixtures. I am now looking for all moneyline-odds for these fixtures. In the XML there are different periods for a game (mostly match and 1st half). Not all of the periods are given for all matches. And if there is a period there does not have to be a moneyline.

So I tried the magic workaround with other data. My code tries to store the other relevant data in scalars and then put all together with the last handler-line. But the data is mixed up.

Replies are listed 'Best First'.
Re^9: How to parse this hash? XML question (Twig example)
by Discipulus (Canon) on Jun 09, 2015 at 12:05 UTC
    Eh no! you need to squeeze yourself a bit more.

    The cur_league tricks works because each event is contained strictly inside a league.

    If the event can contain different items, some of them not required, you need a big handler for the event. In this handler you need to check the presence and the content of required (by you) fields and populate the CSV row accordingly.

    XML::Twig has many (oh really maaany) methods to inspect silb, ancestor, attributes..

    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.