473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

array in perl

Can some one help me to understand the below perl code line:
Expand|Select|Wrap|Line Numbers
  1. 1. my @myarray;
  2.  
  3. 2. $myarray[0][0] {testscore} =0;
  4.  
  5. 3. $myarray[0][0] {testgrade} = "none";
  6.  
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.
Feb 19 '10 #1

✓ answered by RonB

#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).

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6.  
  7. my @myarray;
  8. $myarray[0][0] {testscore} =0;
  9. $myarray[0][0] {testgrade} = "none";
  10.  
  11. print Dumper \@myarray;
Expand|Select|Wrap|Line Numbers
  1. C:\TEMP>test.pl
  2. $VAR1 = [
  3.           [
  4.             {
  5.               'testgrade' => 'none',
  6.               'testscore' => 0
  7.             }
  8.           ]
  9.         ];

3 1922
numberwhun
3,509 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. my %myhash;
  2.  
#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
Feb 19 '10 #2
RonB
589 Expert Mod 512MB
#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).

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6.  
  7. my @myarray;
  8. $myarray[0][0] {testscore} =0;
  9. $myarray[0][0] {testgrade} = "none";
  10.  
  11. print Dumper \@myarray;
Expand|Select|Wrap|Line Numbers
  1. C:\TEMP>test.pl
  2. $VAR1 = [
  3.           [
  4.             {
  5.               'testgrade' => 'none',
  6.               'testscore' => 0
  7.             }
  8.           ]
  9.         ];
Feb 19 '10 #3
numberwhun
3,509 Expert Mod 2GB
You are completely correct. I should actually wake up before replying I guess. :)

Completely missed the brackets signifying the arrays. UGH!!

Regards,

Jeff
Feb 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andrew Fleet | last post by:
Hi, I'm looking at returning a reference to an array I create within a subroutine. I could do this... sub foo { my @theArray; <snip>
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
21
by: scandal | last post by:
I am a javascript newbie working on a script that checks whether a "path" from one element in an array to another is "blocked." Currently, the script pushes an already processed cell index (hence...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
3
by: xedsmr | last post by:
Here is my perl program followed by my output. What am I missing? Thanks so much for any help Write a Perl program that reads a list of strings and then a number (all on separate lines), and...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
5
by: svancouw | last post by:
I just started teaching myself Perl a couple days ago, and am looking forward to what this will give me for my Linux administration skills. Any help on this will be appreciated. I ran into a...
4
by: brian le | last post by:
Hi all, I am new to Perl but really want to learn to do some programming with networking stuffs. I have difficuty writing a Perl script that I wish somebody can help me with. The script I wrote...
1
by: bpejman | last post by:
Hi Everyone, I've been reading and searching the web for days trying to figure out how exactly you can access and read a Perl array or hash from within JavaScript. I've been reading that JSON is...
10
by: J. Peng | last post by:
what's the difference between an array and a list in python? I see list has all features of array in C or perl. so please tell me.thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.