
vikas.deep
User
May 15, 2009, 12:26 AM
Post #16 of 17
(5766 views)
|
Re: [FishMonger] How to populate a Hash
[In reply to]
|
Can't Post
|
|
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
[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
push my @arr, keys %hash; #print Dumper (\%hash) print Dumper (\@arr); prints
[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 push my @arr, values %hash; #print Dumper (\%hash) print Dumper (\@arr); gives
$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)
|