Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

looping in a hashtable

by Ammu (Novice)
on Sep 09, 2012 at 14:12 UTC ( [id://992588]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

It would have been a great if someone giv help in d below reaquirement since i am beginner in Perl.

I have a table store_details in database which looks like below

Account Store day E200 ABC 1 E400 EFG 2

I need to store this in a hashtable(But there wont be any key).Next is to iterate through each rows and get corresponding store numbers for each row.I know the query for that.For eg:I need to put ABC in a query and i will get corresponding store numbers .For eg: for ABC store numbers will be 200,300,400.So i need to creat a new hashtable for which i need to give the corresponding values of ABC to all store numbers.For eg:

Account Store day E200 200 1 E200 300 1 E200 400 1

Like that i need to do for the second row in hashtable also.

Here since 200,300,400 is for ABC store,i will be assigning the other columns values fo rABC to 200,300,400.Can any one help me in this??Pleasee..

Replies are listed 'Best First'.
Re: looping in a hashtable
by NetWallah (Canon) on Sep 09, 2012 at 20:01 UTC
    Your problem statements in recent submissions are rather confusing.

    I think the structure you are seeking is a HASH-OF-ARRAYS. Something like this:

    my %Accountinfo; $Accountinfo{E200} = [200, 300, 400]; $Accountinfo{E400} = ["EFG"]; #Now , you can iterate through all stores for all accounts: for my $acct (sort keys %Accountinfo){ for my $store (@{ $Accountinfo{$acct} } ){ print "Account $acct has store $store\n"; } }
    If this is confusing, please study REFERENCES in perl. (perldoc perlref from a command line).

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Log In?
Username:
Password:

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

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

    No recent polls found