http://qs321.pair.com?node_id=1208325

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi perlmonks, i am writing a script that goes through an xml file reporting about the names and prices. I am having problems aligning the data. This is the xml file:

<breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>Two of our famous Belgian Waffles with plenty of r +eal maple syrup</description> <calories>650</calories> </food> <food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> <description>Light Belgian waffles covered with strawberries an +d whipped cream</description> <calories>900</calories> </food> <food> <name>Berry-Berry Belgian Waffles</name> <price>$8.95</price> <description>Light Belgian waffles covered with an assortment o +f fresh berries and whipped cream</description> <calories>900</calories> </food> <food> <name>French Toast</name> <price>$4.50</price> <description>Thick slices made from our homemade sourdough brea +d</description> <calories>600</calories> </food> <food> <name>Homestyle Breakfast</name> <price>$6.95</price> <description>Two eggs, bacon or sausage, toast, and our ever-po +pular hash browns</description> <calories>950</calories> </food> </breakfast_menu>

And this is the script:

open($fh,"<","xml.xml") or die $!; while(<$fh>){ if($_ =~ /<price>\$(.*)<\/price>/){ push @arr, $1; }elsif($_ =~ /<name>(.*)<\/name>/){ push @ar2,$1; } } @index = sort{$ar2[$a] cmp $ar2[$b]} 0..$#ar2; @har = @ar2[@index]; @har2 = @arr[@index]; $teller = 0; foreach(@har){ print "$_ "; print $har2[$teller]; print "\n"; $teller++; }

I have tried aligning the output-data with the use of spaces and tabs, but i'm not succeeding. Tx for the help.