prod.xmluse XML::Simple; $xml = new XML::Simple( ForceArray => [qw( product color )]); $file = $xml -> XMLin('./prod.xml', ); foreach $products (@{$file->{product}}) { print "Widget: " . $products->{title} ." \n"; print "Rating: " . $products->{rating} . "\n"; print " Cost: " . $products->{cost} . "\n"; print "Colors: " . (join ", ", @{$products->{color}})."\n\n"; }
However, output with a single item for "color" remains empty:<shelf> <product> <title>widget1</title> <cost>0.10</cost> <rating>B</rating> <color>red</color> <color>blue</color> <color>green</color> </product> <product> <title>widget2</title> <cost>0.25</cost> <rating>S</rating> <color>pink</color> <color>gray</color> <color>orange</color> </product> <product> <title>widget3</title> <cost>0.50</cost> <rating>S</rating> <color>white</color> </product> </shelf>
I don't doubt that ForceArrray works, but apparently I just can't figure out the syntax (ie where to plug it in).Widget: widget1 Rating: B Cost: 0.10 Colors: red, blue, green Widget: widget2 Rating: S Cost: 0.25 Colors: pink, gray, orange Widget: widget3 Rating: S Cost: 0.50 Colors:
In reply to Re^4: perl xml and array issue
by dezboi
in thread perl xml and array issue
by dezboi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |