array in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ulnanewbie
    New Member
    • Feb 2010
    • 5

    array in perl

    Can some one help me to understand the below perl code line:
    Code:
    1. my @myarray;
    
    2. $myarray[0][0] {testscore} =0;
    
    3. $myarray[0][0] {testgrade} = "none";
    I understand the code line #1, it is basically declaring the array.

    Can some one help me with the meaning of code line#2 and 3.

    Thanks.
    Last edited by numberwhun; Feb 19 '10, 01:02 PM. Reason: Please use CODE tags!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Since you know what #1 is I won't go into that. But please know that these are not arrays, these are hashes. To be valid though for #2 and #3, #1 would actually have to be:

    Code:
    my %myhash;
    #2 and #3 are referred to as a hash of hashes. Read this link to get a better idea.

    Also, please use code tags around any code you enter in the forums.

    Regards,

    Jeff

    Comment

    • RonB
      Recognized Expert Contributor
      • Jun 2009
      • 589

      #3
      #2 and #3 are referred to as a hash of hashes.
      No, they are not.

      #2 and #3 are AoAoH (an array of arrays of hashes).

      Code:
      #!/usr/bin/perl
      
      use strict;
      use warnings;
      use Data::Dumper;
      
      my @myarray;
      $myarray[0][0] {testscore} =0;
      $myarray[0][0] {testgrade} = "none";
      
      print Dumper \@myarray;
      Code:
      C:\TEMP>test.pl
      $VAR1 = [
                [
                  {
                    'testgrade' => 'none',
                    'testscore' => 0
                  }
                ]
              ];
      Last edited by RonB; Feb 19 '10, 03:02 PM. Reason: Added code example

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        You are completely correct. I should actually wake up before replying I guess. :)

        Completely missed the brackets signifying the arrays. UGH!!

        Regards,

        Jeff

        Comment

        Working...