in reply to XML::Simple - storing/retrieving 2 tables into 1 XML file

As it mentioned in the XML::Simple documentation, the '<anon>' tag is used to form anonymous arrays. You can use the following method for retriving the values if you use '<anon>' tag.
#!/usr/bin/perl -w use strict; use XML::Simple; my $xml = new XML::Simple; my $data = $xml->XMLin("testing.xml"); for (my $i=0;$i<$#{$data};$i++) { if($data->[$i]->{Phones}) { print "\n$data->[$i]->{Phones}->{Manufacturer}"; print "\n$data->[$i]->{Phones}->{Model}"; print "\n$data->[$i]->{Phones}->{Version}"; print "\n$data->[$i]->{Phones}->{Count}"; print "\n==========================="; } }

Replies are listed 'Best First'.
Re^2: XML::Simple - storing/retrieving 2 tables into 1 XML file
by GrandFather (Saint) on Sep 11, 2008 at 10:27 UTC
    for (my $i=0;$i<$#{$data};$i++) { if($data->[$i]->{Phones}) { print "\n$data->[$i]->{Phones}->{Manufacturer}"; ... } }

    is much better written:

    for my $item (@$data) { next unless $item->{Phones}; print "\n$item->{Phones}->{Manufacturer}"; ... }

    Perl reduces RSI - it saves typing
Re^2: XML::Simple - storing/retrieving 2 tables into 1 XML file
by iphony (Acolyte) on Sep 12, 2008 at 05:33 UTC
    Hi folks, thanks for the advice. Finally got it working now!