CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [FishMonger] How to populate a Hash : Edit Log



vikas.deep
User

May 15, 2009, 12:26 AM


Views: 5977
Re: [FishMonger] How to populate a Hash

In my earlier post I said that I will learn how to use quotes/codes this week end because I thought I will have to read some 10-20 pages of perl documentation for that. But I never knew that all I have to do is to try use the buttons already provided here

Following your (FishMonger) code
A data dumperon %hash is giving the following

Code
[root@localhost Documents]# perl bprev.pl 
$VAR1 = {
'A8CLP7_9CNID' => 'MSVIKTDMKIRL------PSKAK',
' => 'MALSN-------------KFIGDDMKM',
' => 'MALSKQ--------------SLPSDMKE',
' => 'MSVIKSVMK------------IKLRMDGIVNK'
};


It is clear that only one Key-Value pair has been initialized but in other cases keys are missing.
Kindly help me to get the keys for other values in this hash to populate this hash

Fearing such a problem I tried to create a "dummy/ toy-hash " yesterday itself with keys as common fruits and there colours as values; that hash was easily populated after Alex's help
butnext when I came back to work for a "true- hash again problems-------

And more to that


Code
push my @arr,  keys %hash;  
#print Dumper (\%hash)
print Dumper (\@arr);


prints

Code
[root@localhost Documents]# perl bprev.pl 
$VAR1 = [
'A8CLP7_9CNID',
', 'GFPL_ANEMA
', 'A8CLP2_MONEF
' 'A7UAL1_9CNID
];

Only the first key is in proper ' ' for all rest the key seems to be 'key\n'
and Dta::Dumper on

Code
push my @arr,  values %hash;  
#print Dumper (\%hash)
print Dumper (\@arr);


gives

Code
$VAR1 = [ 
'MSVIKTDMKIRLQ----SKAK',
'MALSNKFIGDDMKM--------PF',
'MALSKQSLPSD----CFTE',
'MSVIKSVMKIK--------------PIKAK'
];


Surely Sir Data::Dumper makes it easier to guess what is happening where but How to correct what is going wrong here are are the contents of key file


GFPL_ANEMA
A7UAL1_9CNID
A8CLP2_MONEF
A8CLP7_9CNID
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

(This post was edited by vikas.deep on May 15, 2009, 12:58 AM)


Edit Log:
Post edited by vikas.deep (User) on May 15, 2009, 12:58 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives