in reply to Storing an indeterminate number of hash keys in a variable
It'd be easier if you just stored the list of keys in an array ref instead of a string
However, you could just parse the keys and traverse the data structure to find the proper value like so:
use strict; use warnings; my @array = ( '{title}', '{Rule}{Severity}', '{Rule}{weight}', '{Rule}{id}', '{Rule}{version}', '{Rule}{title}', '{Rule}{detailedDescription}{VulnDiscussion}', '{Rule}{detailedDescription}{Responsibility}', '{Rule}{detailedDescription}{IAControls}', '{Rule}{check}{check-content}', '{Rule}{fixtext}{content}', ); for my $firstKey (sort keys %hashData) { for my $arrayKey (@array) { my $val = $hashData{$firstKey}; # Traverse to desired value $val = $val{$1} while $arrayKey =~ /\{(.*?)\}/g; print $val, "\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Storing an indeterminate number of hash keys in a variable
by banesong (Acolyte) on Jul 09, 2011 at 20:06 UTC |
In Section
Seekers of Perl Wisdom