Loading ...
Sorry, an error occurred while loading the content.

The keys of a hash of hashes

Expand Messages
  • Dukelow, Don
    A hash of hashes is being passed to the print_array function with the reference $lic_hash. I can get the keys for the outer hash but keys for the inter hash
    Message 1 of 3 , Sep 30, 2008
    View Source
    • 0 Attachment
      A hash of hashes is being passed to the print_array function with the reference $lic_hash. I can get the keys for the outer hash but keys for the inter hash doesn't want to work on line 73. Can anyone tell me how to get the keys on the inner hash?


      66 sub print_array {
      67 my ($lic_hash, $file) = @_;
      68
      69 open OUT, ">>$$file" or die "\nCan't open file $$file $!\n";
      70 foreach my $key (sort keys (%$lic_hash)) {
      71 print "$key\n";
      72 print OUT "$key\n";
      73 foreach my $feat (sort keys (%{$lic_hash->$key})) {
      74 print "\t$feat\n";
      75 }
      76 }
      77
      78 close OUT;
      79 }
      -----
      Don Dukelow
      e-mail: dukelow@...
    • Jeff Pinyan
      ... Thank you providing well-formatted and easy-to-read code, and for formulating your question clearly. The error on line 73 is that $lic_hash- $key is
      Message 2 of 3 , Sep 30, 2008
      View Source
      • 0 Attachment
        On Tue, Sep 30, 2008 at 1:57 PM, Dukelow, Don <dukelow@...> wrote:

        > A hash of hashes is being passed to the print_array function with the
        > reference $lic_hash. I can get the keys for the outer hash but keys for the
        > inter hash doesn't want to work on line 73. Can anyone tell me how to get
        > the keys on the inner hash?
        >
        > 66 sub print_array {
        > 67 my ($lic_hash, $file) = @_;
        > 68
        > 69 open OUT, ">>$$file" or die "\nCan't open file $$file $!\n";
        > 70 foreach my $key (sort keys (%$lic_hash)) {
        > 71 print "$key\n";
        > 72 print OUT "$key\n";
        > 73 foreach my $feat (sort keys (%{$lic_hash->$key})) {
        > 74 print "\t$feat\n";
        > 75 }
        > 76 }
        > 77
        > 78 close OUT;
        > 79 }
        >

        Thank you providing well-formatted and easy-to-read code, and for
        formulating your question clearly.

        The error on line 73 is that $lic_hash->$key is treating $lic_hash as an
        object and expecting $key to be the name of a method of that object. You
        want to put { and } around $key:

        foreach my $feat (sort keys (%{ $lic_hash->{$key} })) {

        --
        [Mary said,] "Do whatever he tells you." ~ John 2:5
        The Cross Reference - http://thecrossreference.blogspot.com/
        Nos autem praedicamus Christum crucifixum (1 Cor 1:23)


        [Non-text portions of this message have been removed]
      • Dukelow, Don
        I knew it had to be simple it worked, thank you. ... Don Dukelow e-mail: dukelow@hp.com ________________________________ From: perl-beginner@yahoogroups.com
        Message 3 of 3 , Sep 30, 2008
        View Source
        • 0 Attachment
          I knew it had to be simple it worked, thank you.


          -----
          Don Dukelow
          e-mail: dukelow@...



          ________________________________
          From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of Jeff Pinyan
          Sent: Tuesday, September 30, 2008 2:09 PM
          To: perl-beginner@yahoogroups.com
          Subject: Re: [PBML] The keys of a hash of hashes


          On Tue, Sep 30, 2008 at 1:57 PM, Dukelow, Don <dukelow@...<mailto:dukelow%40hp.com>> wrote:

          > A hash of hashes is being passed to the print_array function with the
          > reference $lic_hash. I can get the keys for the outer hash but keys for the
          > inter hash doesn't want to work on line 73. Can anyone tell me how to get
          > the keys on the inner hash?
          >
          > 66 sub print_array {
          > 67 my ($lic_hash, $file) = @_;
          > 68
          > 69 open OUT, ">>$$file" or die "\nCan't open file $$file $!\n";
          > 70 foreach my $key (sort keys (%$lic_hash)) {
          > 71 print "$key\n";
          > 72 print OUT "$key\n";
          > 73 foreach my $feat (sort keys (%{$lic_hash->$key})) {
          > 74 print "\t$feat\n";
          > 75 }
          > 76 }
          > 77
          > 78 close OUT;
          > 79 }
          >

          Thank you providing well-formatted and easy-to-read code, and for
          formulating your question clearly.

          The error on line 73 is that $lic_hash->$key is treating $lic_hash as an
          object and expecting $key to be the name of a method of that object. You
          want to put { and } around $key:

          foreach my $feat (sort keys (%{ $lic_hash->{$key} })) {

          --
          [Mary said,] "Do whatever he tells you." ~ John 2:5
          The Cross Reference - http://thecrossreference.blogspot.com/
          Nos autem praedicamus Christum crucifixum (1 Cor 1:23)

          [Non-text portions of this message have been removed]





          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.