Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

size of an array inside a hash 1

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
How do you get the size of an array inside a hash in 1 step?

this works (2 steps):
$cnt=@{$hash{$key}};
print "cnt is: $cnt\n";

But if I want to do it in 1 step (print):
print "cnt is: @{$hash{key}}\n";
this doesn't work - it returns all the array elements ...


 
That would be the same for all arrays, not just a hash of array. And since "print" is a list operator you have to tell it to print the array in scalar context otherwise it will still print the array but without the default spaces like it does when you double-quote it:

Code:
print 'cnt is: ', scalar @{$hash{key}}, "\n";

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
kev -
That works !!!
I orig. tried prefixing the array with word scalar, but not in the print format that you supplied.

When I use the same print format you suggested it works great !!! Thanks!
 
You're welcome

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
have a star!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top