Solved

shift for a hash?

Posted on 2000-02-28
3
222 Views
Last Modified: 2010-03-05
I want to go through my hash
value for value but with foreach (%hash) $_ becomes a value then a key string then a value etc..


Is there a function for a hash which does the same as shift for an array?

Thanks
0
Comment
Question by:Stapman
  • 2
3 Comments
 
LVL 3

Expert Comment

by:RobWMartin
ID: 2565773
Use this:

foreach (keys %hash)

then

$_ is the key to the hash, and, of course, $hash{$_} is the value.

0
 
LVL 3

Accepted Solution

by:
RobWMartin earned 50 total points
ID: 2565778
I guess I should explain.  The keys function returns an array containing only the key of each hash entry.

For details:

perldoc -f keys


Rob
0
 
LVL 84

Expert Comment

by:ozo
ID: 2566388
#or
while( ($key,$value) = each %hash ){
    print "hash{$key} = $value\n";
}

#also, values %hash returns an array containing only the value of each hash entry
#(the same as @hash{keys %hash})
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now