Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Master Coder
    Join Date
    Apr 2003
    in my house
    Thanked 201 Times in 197 Posts

    trying to retrieve a hash value in loop


    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.

    Last edited by bazz; 09-18-2009 at 01:47 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts