Since you asked for a regex solution:
local our %linked_counts_by_abbr; '' =~ m{(?{ use XML::LibXML qw( ); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($ARGV[0]); my $root = $doc->documentElement(); for my $usage_node ( $root->findnodes('/BookReferences/BookUsage') ) { my $abbr = $usage_node->getAttribute('BookAbbr'); my $linked_count = $usage_node->getAttribute('LinkedCount'); $linked_counts_by_abbr{$abbr} += $linked_count; } })}x;
Personally, I'd drop the regex.
use XML::LibXML qw( ); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($ARGV[0]); my $root = $doc->documentElement(); my %linked_counts_by_abbr; for my $usage_node ( $root->findnodes('/BookReferences/BookUsage') ) { my $abbr = $usage_node->getAttribute('BookAbbr'); my $linked_count = $usage_node->getAttribute('LinkedCount'); $linked_counts_by_abbr{$abbr} += $linked_count; }
In reply to Re: Getting various text into diff. variables using REGEXP
by ikegami
in thread Getting various text into diff. variables using REGEXP
by kdmurphy001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |