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.

how to get the number of keys in an hash

Hi,

I need to get the number of keys in an hash. Is there any convenient way to
get it?

or use the following one?
foreach $v (keys %hash){
$count++;
}

Thanks in advance,
Liang
Jul 19 '05 #1
7 33124
Liang wrote:
Hi,

I need to get the number of keys in an hash. Is there any convenient
way to get it?

or use the following one?
foreach $v (keys %hash){
$count++;
}


Oh dear, that's a rather creative way....

Trivial. Just use "keys(%hash)" in scalar context, e.g.
my $number = keys %hash;

jue
Jul 19 '05 #2
"Liang" <le*********@hotmail.com> wrote in message news:<cg**********@newshost.mot.com>...
Hi,

I need to get the number of keys in an hash. Is there any convenient way to
get it?

or use the following one?
foreach $v (keys %hash){
$count++;
}

Thanks in advance,
Liang

Try

$keyCount=(%keys %hash);
Jul 19 '05 #3
"Liang" <le*********@hotmail.com> wrote in message news:<cg**********@newshost.mot.com>...
Hi,

I need to get the number of keys in an hash. Is there any convenient way to
get it?
Yes, the keys() function.
or use the following one?
foreach $v (keys %hash){
$count++;
}
No, that is not necesary.

This newsgroup does not exist (see FAQ). Please do not start threads here.
Thanks in advance,


If you are going to do any things "in advance" then my suggestions would be:

1) Check the FAQ.
2) Check the documentation for the functions you are using.
Jul 19 '05 #4
Everyone says "See FAQ". Could you please include the URL to the FAQ?
Be kind to newbies......You used to be one.

-s

no****@mail.com wrote:

"Liang" <le*********@hotmail.com> wrote in message news:<cg**********@newshost.mot.com>...
Hi,

I need to get the number of keys in an hash. Is there any convenient way to
get it?


Yes, the keys() function.
or use the following one?
foreach $v (keys %hash){
$count++;
}


No, that is not necesary.

This newsgroup does not exist (see FAQ). Please do not start threads here.
Thanks in advance,


If you are going to do any things "in advance" then my suggestions would be:

1) Check the FAQ.
2) Check the documentation for the functions you are using.

Jul 19 '05 #5
Steve Bennett wrote:
Everyone says "See FAQ". Could you please include the URL to the FAQ?


What happens when you do a Google search on "perl faq"?
Newbies are expected to know that Google is their friend.
Jul 19 '05 #6
Steve Bennett wrote:
Everyone says "See FAQ". Could you please include the URL to the FAQ?
No need for a URL, it's on your own harddrive (after you installed Perl)
Just type
perldoc perlfaq
Be kind to newbies......You used to be one.


You also seem to be new to Usenet. It is considered rude to
- top post
- blindly full quote
For an explanation of what that is and why it's considered rude please
search www.google.com

jue
Jul 19 '05 #7
Steve Bennett rudely spits TOFU in may face:
Everyone says "See FAQ". Could you please include the URL to the FAQ?
You are supposed to look for a FAQ _before_ you ask a question. It
would defeat the purpose if the FAQ was so hard to find that asking
where it was was a ligitimate question. Anything you could reasonably
imagine doing to locate the Perl FAQ will succede in about fifteen
seconds.
Be kind to newbies.


I am. Teaching newbies that selfishness is rewarded is _not_ a
kindness.
Jul 19 '05 #8

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

Similar topics

2
by: Tommo | last post by:
Hello All, I have a slight problem that goes like this. I have created a Perl hash where the keys are made up of numeric values, I was then sorting the 'keys' for this hash on their value (a<=>b...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
2
by: amywolfie | last post by:
This is an interesting one..... I have a field on FORM!FORMDATA (no, I did not name this) called KEY. There can be multiple KEYS per record (equates to FIELDS on a given DOCUMENT). The...
6
by: Jovo Mirkovic | last post by:
Hi, I have to make a program which will generate 100,000 different ID numbers (for example 2345-9341-0903-3432-3432 ...) It must be really different, I meen it can not be a similar (like...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
5
numberwhun
by: numberwhun | last post by:
Ok, I have a ".csv" file that contains two lines (VERY LONG lines). Basically, the first line is the headers defining what each field in the second line is. ie: Name1,Name2,Name3,...........
1
by: pavanponnapalli | last post by:
hi , I have got a code as under : sub dbcall { my %hash; my $i=0; print "<<<<<<<@_>>>>>>> \n"; foreach(@_)
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.