my %struct;
foreach my $elem (@elements) { # loop over all the elements
# check to make sure our hash key has an array we can push onto.
$struct{$elem->name}=[] unless $struct{$elem->name};
# now create a new sub hash to push onto the array later
my %hash=(text=>$elem->text, attributes=>[]); #initialize it
# loop over each attribute in the element
foreach my $attrib ($elem->attribs) {
# push the elements onto the attributes array
push @{$hash{attributes}},$attrib->name,$attrib->value;
}
# push a reference to the newly created hash on the array stored for this element type.
push @{$struct{$elem->name}},\%hash;
}
####
push @{$hash{$key}},'var' unless @{$hash{$key}}>5;
####
push @{$hash{$key}},'var' unless @{$hash{$key}||[]}>5;