Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Size of list pointed by key, in a hash

Reply
Thread Tools

Size of list pointed by key, in a hash

 
 
bravetanveer
Guest
Posts: n/a
 
      03-03-2006
Hi friends,

I am facing a problem with hashes::

My hash is declared as below::


%HashTestSuites_TestCases = (

"ts_Apu" => [ "tc_Apu2LevelForNegIndexTernary",
"tc_Apu2LevelForsobelEDBenchmark_16_16",
tc_Apu2LevelForsobelEDBenchmark_88", "tc_ApunoNest",
"tc_ApuUgdOnceReservZeroReserv"],

"ts_DB_LoopFuse" => ["tc_DL_1LevelForDwt",
"tc_DL_2LevelFor2FilesMacro", "tc_DL_2LevelForNegIndexTernary",
"tc_DL_2LevelForSobelBenchMark", "tc_DL_2LevelForStructIntArray",
"tc_DL_2LevelForStructShortArray", "tc_DL_4LevelForNoHB_LaplaceED",
"tc_DL_forInSwitchCase", "tc_DL_noNest", "tc_DL_ugdMultReuse"]

);

foreach $testSuite ( keys %HashTestSuites_TestCases )
{

my $temp = scalar ( $HashTestSuites_TestCases{$testSuite} );

print "Size is $temp ";
print "Size is $#HashTestSuites_TestCases{$testSuite} ";

}


both of the print statements do not give me size. As far as i know
these are the only ways to get size of array .

Why am i not getting the size printed of the list to which teh key is
pointing to ???

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      03-03-2006
bravetanveer wrote:
>
> I am facing a problem with hashes::
>
> My hash is declared as below::
>
>
> %HashTestSuites_TestCases = (
>
> "ts_Apu" => [ "tc_Apu2LevelForNegIndexTernary",
> "tc_Apu2LevelForsobelEDBenchmark_16_16",
> tc_Apu2LevelForsobelEDBenchmark_88", "tc_ApunoNest",
> "tc_ApuUgdOnceReservZeroReserv"],
>
> "ts_DB_LoopFuse" => ["tc_DL_1LevelForDwt",
> "tc_DL_2LevelFor2FilesMacro", "tc_DL_2LevelForNegIndexTernary",
> "tc_DL_2LevelForSobelBenchMark", "tc_DL_2LevelForStructIntArray",
> "tc_DL_2LevelForStructShortArray", "tc_DL_4LevelForNoHB_LaplaceED",
> "tc_DL_forInSwitchCase", "tc_DL_noNest", "tc_DL_ugdMultReuse"]
>
> );
>
> foreach $testSuite ( keys %HashTestSuites_TestCases )
> {
>
> my $temp = scalar ( $HashTestSuites_TestCases{$testSuite} );


You have to dereference the array to get its size:

my $temp = @{ $HashTestSuites_TestCases{$testSuite} }


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-03-2006
"bravetanveer" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> My hash is declared as below::
>
>
> %HashTestSuites_TestCases = (
>
> "ts_Apu" => [ "tc_Apu2LevelForNegIndexTernary",
> "tc_Apu2LevelForsobelEDBenchmark_16_16",
> tc_Apu2LevelForsobelEDBenchmark_88", "tc_ApunoNest",
> "tc_ApuUgdOnceReservZeroReserv"],
>
> "ts_DB_LoopFuse" => ["tc_DL_1LevelForDwt",
> "tc_DL_2LevelFor2FilesMacro", "tc_DL_2LevelForNegIndexTernary",
> "tc_DL_2LevelForSobelBenchMark", "tc_DL_2LevelForStructIntArray",
> "tc_DL_2LevelForStructShortArray", "tc_DL_4LevelForNoHB_LaplaceED",
> "tc_DL_forInSwitchCase", "tc_DL_noNest", "tc_DL_ugdMultReuse"]
>
> );


Please format your code in a way that makes it easier for others to read
(you would benefit from this as well). By the way, have you read the
posting guidelines for this group?

You should not prefix the name of you variable with the word 'Hash'.
After all, that is why we use %: to denote that a variable is a hash
table.

use strict;
use warnings;

my %Suites = (
ts_Apu => [ qw(
tc_Apu2LevelForNegIndexTernary
tc_Apu2LevelForsobelEDBenchmark_16_16
tc_Apu2LevelForsobelEDBenchmark_88
tc_ApunoNest
tc_ApuUgdOnceReservZeroReserv
)],
ts_DB_LoopFuse => [ qw(
tc_DL_1LevelForDwt
tc_DL_2LevelFor2FilesMacro
tc_DL_2LevelForNegIndexTernary
tc_DL_2LevelForSobelBenchMark
tc_DL_2LevelForStructIntArray
tc_DL_2LevelForStructShortArray
tc_DL_4LevelForNoHB_LaplaceED
tc_DL_forInSwitchCase
tc_DL_noNest
tc_DL_ugdMultReuse
)]
);

> foreach $testSuite ( keys %HashTestSuites_TestCases )


for my $suite ( keys %Suites )

> {
>
> my $temp = scalar ( $HashTestSuites_TestCases{$testSuite} );
>
> print "Size is $temp ";
> print "Size is $#HashTestSuites_TestCases{$testSuite} ";
>
> }
>
>
> both of the print statements do not give me size.


Of course not. There is a simple reason for that: You can't make stuff
up and expect it to work.


> As far as i know these are the only ways to get size of array .


But you never dereferenced those array references!

for my $a_suite ( keys %Suites ) {
print "Suite $a_suite test cases: ",
scalar @{ $Suites{$a_suite} }, "\n";
}

See perldoc perlreftut.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
bravetanveer
Guest
Posts: n/a
 
      03-03-2006
Thanks John an Sinan.

Good to learn lot from you people. Next time , i will make sure, i
don't make those formatting mistakes.

 
Reply With Quote
 
bravetanveer
Guest
Posts: n/a
 
      03-03-2006
Thanks John an Sinan.

Good to learn lot from you people. Next time , i will make sure, i
don't make those formatting mistakes.

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-03-2006
"bravetanveer" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> Thanks John an Sinan.
>
> Good to learn lot from you people. Next time , i will make sure, i
> don't make those formatting mistakes.


You are welcome. I will ask that you please read the posting guidelines
for this group as well as

http://www.safalra.com/special/googlegroupsreply/

and

http://cfaj.freeshell.org/google/

for future reference.

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
how to determine the size of memory pointed by a int pointer? Paul C Programming 6 11-29-2007 09:55 PM
Size of memory Pointed-to Winsk C Programming 4 10-08-2007 09:18 AM
Need to know the size of the memory block pointed to by a char* Frodo Baggins C Programming 12 01-03-2007 12:19 PM



Advertisments