in reply to Re: References for subroutines to Hashes in Hashes :)
in thread References for subroutines to Hashes in Hashes :)

damn thats great work of you...

but no troubles with the -----

I just putted it that way to give you a vision of the normalisation of my Query. I get my data from Oracle 8, so I just name th collumns....

but my mayor question about the reference seems awsered so that should bring me further. Is my subroutine correct written, will be able to receive that reference and work with it?

Much thanks
Merlijn

  • Comment on Re: Re: References for subroutines to Hashes in Hashes :)

Replies are listed 'Best First'.
Re: Re: Re: References for subroutines to Hashes in Hashes :)
by suaveant (Parson) on Aug 17, 2001 at 18:17 UTC
    ahh yes, I'd missed the database calls...
    What are the fields your database returns? Your hash does look ok, but I would probably put the AM0 AM1 etc in an array, not a hash... something like...
    for $key (keys %$c) { next unless $key =~ /^[AP]M_\d+$/; push @{$a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}}, $c->{$key} if $c->{$key}; }
    Not tested, but should work... that should go through the keys, matching any that start with AM or PM with an _ and the a number, and push them into an anonymous array if they have a value... this is assuming AM_0 AM_1 etc just hold a 1 or 0 for a yes or no... }

                    - Ant
                    - Some of my best work - Fish Dinner

      suaveant, I love ya :)

      your last awnser just helped me out, Thanks alot!!

      it's 18.24 PM here, so gonna quit, ah just such a relief.....

      have a nice weekend all, bye.

      Merlijn

      Good idea about that last array, but this are troubles for in a later stadia....

      I been coding just a bit and there still seems a trouble...

      lets say hashfilling is ok...

      while (my $c = $st->fetchrow_hashref) { my %analyst_record; $analyst_record{$c->{ANA_ID}}{e_mail}=$c->{EMAIL}; print STDERR "Hash: $analyst_record{$c->{ANA_ID}} \n"; Show_analyst_row($analyst_record{$c->{ANA_ID}}); ... ... ... sub Show_analyst_row { my(%analyst_record)=%{@_}; print STDERR "sub: $analyst_record{description} \n"; print "Valerie $analyst_record{description} \n"; print "</TR>\n"; }

      So I did remove the \ for the reference...

      But still he only prints "valerie" for every record in the query, Is it possible that there is still something wrong in the receiving of the reference cause when I just print and don't call the subfunction he does print the E-mail(uderstand what I mean?)

      here is the log of my errorlog(notice the prints I putted in the code for that)

      Hash: HASH(0x4039b1f0) sub: Hash: HASH(0x4039b1d8) sub: Hash: HASH(0x4037dfbc) sub: Hash: HASH(0x4039b3c4) sub: Hash: HASH(0x4039b3b8) sub: Hash: HASH(0x403aa028) sub: Hash: HASH(0x4039b214) sub:

      thanks for looking.
      Merlijn
      aye great tip Ant,

      I got for every key before I call the subroutine the correct value of the Hash. eg.

      1234 HASH(0x403aab28)
      but when I repeat this statement in the subroutine I receive nothing, completely nothing, how odd...

      sub Show_analyst_row { my(%analyst_record)=%{@_}; print STDERR (join "\n", %analyst_record); }

      above code generates nothing, I would think ther is something wrong in receiving the reference no?

      Any idea's?

      Thanks for looking
      Merlijn

        ooh, I think your problem is here...
        my(%analyst_record)=%{@_};
        change this to
        my(%analyst_record)=%{$_[0]};
        or my(%analyst_record)=%{shift};

                        - Ant
                        - Some of my best work - Fish Dinner

      Good idea about that last array, but this are troubles for in an later stadia....

      I been coding just a bit and there still seems a trouble...

      lets say hashfilling is ok...

      while (my $c = $st->fetchrow_hashref) { my %analyst_record; $analyst_record{$c->{ANA_ID}}{e_mail}=$c->{EMAIL}; print STDERR "Hash: $analyst_record{$c->{ANA_ID}} \n"; Show_analyst_row($analyst_record{$c->{ANA_ID}}); ... ... ... sub Show_analyst_row { my(%analyst_record)=%{@_}; print STDERR "sub: $analyst_record{description} \n"; print "Valerie $analyst_record{description} \n"; print "</TR>\n"; }

      So I did remove the \ for the reference...

      But still he only prints "valerie" for every record in the query, Is it possible that there is still something wrong in the receiving of the reference cause when I just print and don't call the subfunction he does print the E-mail(uderstand what I mean?)

      here is the log of my errorlog(notice the prints I putted in the code for that)

      Hash: HASH(0x4039b1f0) sub: Hash: HASH(0x4039b1d8) sub: Hash: HASH(0x4037dfbc) sub: Hash: HASH(0x4039b3c4) sub: Hash: HASH(0x4039b3b8) sub: Hash: HASH(0x403aa028) sub: Hash: HASH(0x4039b214) sub:

      thanks for looking.
      Merlijn
        in your code above you never populate $a_record{$c->{ANA_ID}}{description}
        here is a trick I do when debugging hashes...
        print (join "\n", %analyst_record);
        that will print
        key
        value
        key
        value
        etc...

                        - Ant
                        - Some of my best work - Fish Dinner