Trying to extract information from a XML file using this piece of snippet, I'm not getting the desired output as intended and I know its something within the foreach loop, -> My question how one can use the foreach loop in this case
use strict;
use XML::Simple;
use Data::Dumper;
my %top_in_ou_bi;
$top_in_ou_bi{"input"}{name}=add;
$top_in_ou_bi{"input"}{name}=clk;
$top_in_ou_bi{"input"}{name}=dat_in;
$top_in_ou_bi{"output"}{name}=dat_out;
$top_in_ou_bi{"bidirection"}{name}=ctrl;
foreach my $nam(sort keys %top_in_ou_bi){
foreach my $dat(keys %{$top_in_ou_bi{$nam}}){
print"$nam $dat: $top_in_ou_bi{$nam}{$dat}\n";
}
}
output:
bidirection name: ctrl
input name: dat_in
output name: dat_out
Expected output:
bidirection name: ctrl
input name: dat_in
input name: clk
input name: add
output name: dat_out
also using "use strict" warns that barewords are not allowed, how one can surpass this warning!
Thanks!
EDIT
I'd like to know if the below snippet is a valid one?
my $top_in=$root_top->{input};
my $top_ou=$root_top->{output};
my $top_bi=$root_top->{bidirection};
foreach my $name(keys %$top_in)
{
print "input $name\n";
}
foreach my $name(keys %$top_ou)
{
print "output $top_ou->{name}\n";
}
foreach my $name(keys %$top_bi)
{
print "bidirection $top_bi->{name}\n";
}