Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

beginnner perl hash question

by jimmy78 (Initiate)
on Feb 16, 2009 at 21:16 UTC ( [id://744204]=perlquestion: print w/replies, xml ) Need Help??

jimmy78 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a text file of form A B C 123 34 45 234 45 67 .. .. I want to create a hash where A should be the key and B and C can be retreived from A. And I want to create 24 such hashes through for loop. Can somebody please tell the way to initalize such a hash and access it in for loops ? I need this to be done asap and I am not expert at it and just getting confused. Jimmy

Replies are listed 'Best First'.
Re: beginnner perl hash question
by Corion (Patriarch) on Feb 16, 2009 at 21:18 UTC

    I think the best start is perldsc, or some other text on anonymous data structures. This is not something that you can learn "asap", but you can start now.

      Thks.. This is helpful... I think I found my implementation already reading this:->

        Huh? You first say

        "so, what kind of hash should this be ? The link you said has a list of all sorts of hashes."
        and then, 17 minutes later, go on to say
        "Thks.. This is helpful... I think I found my implementation already reading this:-> "
        (Exact quotes included in case the nodes get edited.)

        What has changed? The main reason I ask is because others may have the same trouble you have had and they will be able to follow your trail if you provide the resources to.

        And you didn't even know bears could type.

      so, what kind of hash should this be ? The link you said has a list of all sorts of hashes.
Re: beginnner perl hash question
by n3toy (Hermit) on Feb 17, 2009 at 05:52 UTC
    You can initialize your hash with:

    %hash = ();

    And access it later on (after it is populated) in a loop like so:

    foreach $key (keys %hash) { print $hash{$key} . "\n"; }

    You can also look around the Monastery. This might be some good reading for you: QandASection: hashes

    Jamie

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://744204]
Approved by sweetblood
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found