Hi,

I'm a Perl newbie. I have the following in myfile.xml

<detail> <start> <nonterminal name="A" /> </start> <rules> <rule name="A" type="text"> <nonterminal name="AA" /> <nonterminal name="AC" /> <nonterminal name="AD" /> <nonterminal name="AB" /> <nonterminal name="AE" /> </rule> <rule name="AA" type="numeric"> <token>1</token> <token>10</token> </rule> <rule name="AC" type="alpanumeric"> <token>3</token> <nonterminal name="BE" /> <nonterminal name="CE" /> <token>30</token> </rule> <rule name="CE" type="special"> <token>var1</token> <token>var2</token> </rule> <rule name="BE" type="symbol"> <token>%</token> <token>#</token> </rule> </rules> </detail>

My program to read the above:

use XML::Simple; use Data::Dumper; my $file_name = "myfile.xml"; my $xmlObj = XML::Simple->new(); my $data = $xmlObj->XMLin($file_name); my $primitive = 'A' foreach my $mydata(keys %{$data->{rules}{rule}{$primitive}{nontermin +al}}) { print $mydata; print " "; }

The output I got is AC AA AE AB AD but I wanted it in its original position, ie, AA AC AD AB AE
and how would I print a mix of nonterminal and token (as in rule AC)?
Please help.


In reply to XML::Simple How to print data in its original position by Z_S

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.