Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

looping in a hashtable

by Ammu (Novice)
on Sep 09, 2012 at 14:12 UTC ( #992588=perlquestion: print w/replies, xml ) Need Help??
Ammu has asked for the wisdom of the Perl Monks concerning the following question:


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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992588]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2018-04-20 00:14 GMT
Find Nodes?
    Voting Booth?