How do you extract the values/attributes from all the XML tags using Perl and output them once Example XML

<Root> <tags> <first name="AA"> <A1 name="A"/> <B1 name="B"/> </first> <second name="BB"> <A1 name="A"/> <B1 name="B"/> <C1 name="C"/> </second> <Third name="CC"> <A1 name="A"/> <B1 name="B"/> <C1 name="C/> </Third> <Fourth name="DD"> <A1 name="A"/> <B1 name="B/> <C1 name="C/> </Fourth> </tags> <Root>

Output: I just need the output which is:

A B C
Any help is appreciated Note:I'm using XML::Simple, I know XML::Simple is not that easy. Kindly do post a example code just for reference. Because I'm unclear where to start

Original node content restored above by GrandFather

how to declare wires for verilog using perl. The XML data has the following information for modules which is needed Example XML

<Root> <tags> <Module ="AA"> <Input name="cpu_control"/> <Output name="power_control"/> </first> <module="BB"> <Input name="data_b"/> <output name="data_out"/> <bidirection name="add_bus"/> </second> <Module="CC"> <Input name="power_con"/> <Bidirection name="data_b"/> </Third> </tags> </Root>

I'm trying to generate a wire declaration for verilog using perl scripting. I however have an idea on how to do it, but less clue on implementing it. The Idea I have is, "foreach lower module the signals of inputs, outputs, inouts(bidirection) if not present in the top module then these should be declared as wires."

sample output: wire power_control; wire add_bus; wire cpu_control;
My code use warnings; use XML::Simple; use Data::Dumper; my $xml=XMLin('sample.xml'); my $roottags=$xml->{tags}; my $topmodule=$roottags->{Module}; my @mod=keys %$topmodule; foreach my $modules(values %$topmodule) { my $modu_temp=shift(@mod); #print "$modu_temp\n"; #my $ins_mod=$modules->{input}; my @ins=(keys %{$modules->{input}}); if(exists $ins[0]){} else{ $in_1=$modules->{input}; @ins=$in_1->{name}; } print @ins, "\n"; }

Is my logic close enough? because I get the output which I dont want

Any help is appreciated Note:I'm using XML::Simple, I know XML::Simple is not that easy. Kindly do post a example code just for reference. Because I'm unclear where to start


In reply to Extract attributes/values from XML using perl / declaring wires in verilog using perl by gr.d

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.