...

View Full Version : trying to retrieve a hash value in loop



bazz
09-18-2009, 12:45 PM
Hi,

Made good progress on hashes but I am stuck again. I am trying to run a loop and within it, a conditional relative to a hash value. can't seem to work it out after a lot of attempts.



while (my ($age, $terms_abbr) = each %ages_terms_number){

while (my ($terms_abbr, $numbers) = each %$terms_abbr ) {

if ( $ages_terms_number{'Adult'}{'prpn'} # ok
&& $ages_terms_number{$age}{'pacpn'} > 0 ) { # not getting the value
do something;
}
}
}




the hash is like this



'ages_terms_number' => {
'Up to 10 yrs' => {
'pacpn' => '1'
},
'Up to 5 yrs' => {
'pacpn' => '1'
},
'Adult' => {
'prpn' => '1'
}
},


There may be several different 'children' ages and I think the only common feature is the terms (pacpn), which each of the children's prices will have. I think the $age var might be throwing it off so how would I get the value when the * won't work in place of the $age var.


I wonder if i should
a. put the red text into its own 'if' clause (within the other one) and use a regex to identify the numerical part of the keys or,
2. change the 2 while loops into 3 foreach loops and get the actual value I need

3. find a way to grab the value (index the hash?), to get the required data

4. your own experienced method.



bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum