The XML parsing in your code seems ... odd. Can you provide a sample of the XML input? Is it really XML-encoded CSV or does the input actually have structure? If I read the code correctly, your XML parsing is implicitly assuming that all of the XML fields will be in the same order in every record.
Maybe something like:
my @items; for my $record (@records) { my %item = (); for my $tag ($record->children) { $item{$tag->name} = $tag->text } push @items, {%item}; }
This gets rid of all of the $*_pos variables and directly converts XML to an array of hashes for further processing.
The series of regex substitutions can go in their own sub cleanup. Then change the relevant line to $item{cleanup $tag->name} = cleanup $tag->text assuming that cleanup is declared with the appropriate prototype.
sub cleanup ($) { my $work = shift; $work =~ s/\r|\n//g; # Cleanup Carraige Returns $work =~ s/, / /g; # Cleanup Comma Space $work =~ s/,/ /g; # Cleanup Comma $work =~ s/"//g; # Cleanup Parentheses $work =~ s/^\s+|\s+$//g; # Trim spaces $work =~ s/([^[:ascii:]]+)/unidecode($1)/ge; return $work; }
This will create some differences, for example, $data[$class_pos] is now $items[$n]{sys_class_name} after the XML parsing loop, where $n is an index into the @items array.
In reply to Re: Need help with complex hash of hashes.
by jcb
in thread Need help with complex hash of hashes.
by vlturner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |