What is the better method for using hash??

S

sonet

How to compare the memory usage??What is the better??

(A)
hash1{TYPE1}{VALUE1}='A';
hash1{TYPE1}{VALUE2}='B';
hash1{TYPE1}{VALUE3}='C';
hash1{TYPE2}{VALUE1}='1';

or
(B)
TYPE1{VALUE1}='A';
TYPE1{VALUE2}='B';
TYPE1{VALUE2}='C';
TYPE2{VALUE1}='1';

How can i do that (A) hash keys as refs?
 
G

Gunnar Hjalmarsson

sonet said:
How to compare the memory usage??What is the better??

(A)
hash1{TYPE1}{VALUE1}='A';
hash1{TYPE1}{VALUE2}='B';
hash1{TYPE1}{VALUE3}='C';
hash1{TYPE2}{VALUE1}='1';

or
(B)
TYPE1{VALUE1}='A';
TYPE1{VALUE2}='B';
TYPE1{VALUE2}='C';
TYPE2{VALUE1}='1';

How can i do that (A) hash keys as refs?

perldoc perlreftut
perldoc perlref
 
X

xhoster

sonet said:
How to compare the memory usage??

I'd do it by measuring their memory usages (on a large enough sample), and
then comparing them. I find this to be convenient if not very portable:
print +(`ps -p $$ -o rss `)[1];

What is the better??

(A)
hash1{TYPE1}{VALUE1}='A';
hash1{TYPE1}{VALUE2}='B';
hash1{TYPE1}{VALUE3}='C';
hash1{TYPE2}{VALUE1}='1';

or
(B)
TYPE1{VALUE1}='A';
TYPE1{VALUE2}='B';
TYPE1{VALUE2}='C';
TYPE2{VALUE1}='1';

Neither is better. A is a syntax error, and B has nothing to do with
hashes (and is also a syntax error if you use strict).

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top