472,958 Members | 2,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

references

I am studying the examples in the book "Perl 5 by Examples". Here's a
short program from that book:

my $dbf2 = { 3 => { 4=>5, 5=>6 } };
my($key1,$value1,$key2,$value2);
while (($key1,$value1) = each(%{$dbf2})) {
print("level 1: $key1 => $value1\n");
while(($key2,$value2) = each(%{$value1})) {
print("level 2: $key2 => $value2\n");
}
}

The program would prints:

Level 1: 3 => HASH(123456)
Level 2: 4 => 5
Level 2: 5 => 6

Now, what if I create this (which passed the compilation):

my $dbf3 = { { 4=>5, 5=>6} }

How could I make the same program work?

--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 4:54pm up 2 days 18:48 load average: 1.00 1.00 1.00
Jul 19 '05 #1
2 1399
toylet wrote:
I am studying the examples in the book "Perl 5 by Examples". Here's a
short program from that book:

my $dbf2 = { 3 => { 4=>5, 5=>6 } };
my($key1,$value1,$key2,$value2);
while (($key1,$value1) = each(%{$dbf2})) {
print("level 1: $key1 => $value1\n");
while(($key2,$value2) = each(%{$value1})) {
print("level 2: $key2 => $value2\n");
}
}

The program would prints:

Level 1: 3 => HASH(123456)
Level 2: 4 => 5
Level 2: 5 => 6

Now, what if I create this (which passed the compilation):

my $dbf3 = { { 4=>5, 5=>6} }

How could I make the same program work?

What are you trying to accomplish? In $dbf2 you have a hash that has
one key/value pair. Key name "3" that has a value that is another hash
has 2 key/value pairs. When you defined $dbf3 you have defined a hash
that has a single key/value pair the key is a hash and the value is
undefined.

To better see what data structures you have created try using
Data::Dumper module.
Here is what Dumper gives you for you two hashes:
(This is $dbf2)
$VAR1 = {
'3' => {
'4' => 5,
'5' => 6
}
};

(This is $dbf3)
$VAR1 = {
'HASH(0x8260d54)' => undef
};


--
Thanks
Charles LaCour
Jul 19 '05 #2
thank you for the tip on Data::Dumper. I was just testing my skills on
accessing data structures of Perl.
To better see what data structures you have created try using
Data::Dumper module.
Here is what Dumper gives you for you two hashes:
(This is $dbf3)
$VAR1 = {
'HASH(0x8260d54)' => undef
};


--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 10:50am up 23 min 0 users 1.12 1.07
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using...
22
by: xmp333 | last post by:
Hi All, I am trying to hide my JavaScript source. The method I chose was to keep all the important source in a password protected folder, and then use a SRC="folder/script.js" to include it...
33
by: JKop | last post by:
I understand variables/objects and pointer variables perfectly: int X = 5; int* pX = &X; *pX = 4; int** ppX = &pX:
2
by: S. van Beek | last post by:
Dear reader, For removing a reference in the VBA reference form I receive from Doug Steele the following code: ........... References.Remove refCurr
11
by: codebloatation | last post by:
I know how to use references but i DO not get WHY they exist other than to add to the language. Are they actually needed for anything?
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
30
by: jeremygetsmail | last post by:
I've got an adp (Metrix.adp) with a reference to another adp (InteractSQL.adp). InteractSQL sits on a server, and is refered to by all of the clients (Metrix), which sit on the client machines...
3
by: DonJefe | last post by:
Does anyone have experience using project->project references in large solutions? What are the plus/minuses that you have found? Currently, we are using the binary assembly references for our...
9
by: igor.kulkin | last post by:
References is a relatively basic feature of C++ language. It might be a good thing to think of references as aliases to the variables. However it's good to think of references this way when you...
3
by: CenturionX | last post by:
Hello everybody: I'd like to know what references in my vba code are used or not. I work in a code made by another person previously, i founded to many references and i believe that someones...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.