<Root>
<Top Name=" ">
<Tag name="ALU">
<in name="PC"/>
<iodirection name="AB"/>
</Tag>
<Tag name=" ">
<in name="CCB"/>
<ou name="PC"/>
<bi name="AB"/>
</Tag>
<Tag name=" ">
<in name="DB"/>
<ou name="DI"/>
<bi name="CCB"/>
</Tag>
<Tag name=" ">
<in name="DI"/>
<ou name="DB"/>
<bi name="CCB"/>
</Tag>
</Top>
</Root>
I'm not a Perl expert, but some simple things are hard for me to figure out and one such task is this. The above XML as you can see the attributes/elements, they're repeated couple of times but for different <in>
, <io>
and <ou>
tags. Now I'm looking to return only the repeated attributes/elements and just print them once.
Example : DI
DB
CCB
AB
My code snippet goes something like this
use strict;
use XML::Simple;
use Data::Dumper;
$xml_1 = XMLin('./tmp.xml');
my $root_top = $xml_1->{Top};
my $mod_top = $root_top1->{Tag};
my @mod = keys %$mod_top;
foreach my $mods ( values %$mod_top ) {
my $temp = shift(@mod);
print XST_FILE "$temp u_$temp(\n";
my $in_mo = $modules->{in};
my @in_1 = keys %$in_mo;
foreach my $name_1 ( values %$in_mo ) {
my $inn = shift(@in_1);
if ( $inn =~ /\bname\b/ ) {
print " \.$name_1\($name_1\)\,\n";
}
else {
print " \.$in\($in\)\,\n";
}
}
PS: I'd appreciate it if this can be modified only in XML::Simple
. Though XML::Simple is discouraged, he's not righteous, but he is the one I'm currently using just to finish this task