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: [alex_v2] How to populate a Hash : Edit Log



vikas.deep
User

May 14, 2009, 10:41 AM


Views: 6777
Re: [alex_v2] How to populate a Hash

At the end of a long-long day I am back to zero and again the same problem "How to polpulate a hash"
First my code

open (my $FH, 'parse21.txt') or die "Cannot open the file parse21.txt: $!";
open (my $FHH, '>parse211.txt') or die "Cannot open the file parse212.txt: $!";
@key = <$FH>;
chomp (@key);
my $arref = \@key;
my $gb = Bio::DB::SwissProt->new;
my $seqio = $gb -> get_Stream_by_id($arref);
while (my $clone = $seqio->next_seq )
{
print $FHH $clone ->seq,"\n";
}close $FHH;
open (my $FHHH, 'parse211.txt') or die "Cannot open the file parse211.txt: $!";
@value = <$FHHH>;
chomp (@value);
@h{@key} = @value;
print $h{'GFPL_ANEMA'};

Again the same (dreaded) output
#[root@localhost Documents]# perl bp.pl
#Use of uninitialized value in print at bp.pl line 46, <$FHHH> line 4.

Here a few classes of Bio:Perl are used which fetch some biological sequences from online databases like SWISS-PROT; None of which should matter. At the heart of the problem is a key file which has been opened using $FH and a value file which has been opened twice once for writing with a file handle $FHH and then a second time for reading using $FHHH.
Surprisingly a
print keys %h
does not prints anything while
print values %h prints what is expected and
print %h prints what is expected only for the last key and for the rest it is just printing the values!.
Also if @key is not chomped then keys ARE PRINTED!!
the parse21.txt(or $FH) file carries the keys
#GFPL_ANEMA
#A7UAL1_9CNID
#A8CLP2_MONEF
#A8CLP7_9CNID
and parse211.txt($FHH) carries the values
#MALSNKFIGDDMKMTYHMDGCVNGHYFTVKGEGNGK
#MSVIKSVMKIKLRMDGIVNGHKFMITGEGEGKPFEG
#MALSKQSLPSDMKLIYHMDGNVNGHSFVIKGEGEGK
#MSVIKTDMKIRLQMQGAVNGHPFVITGEGEGKPYEG

FrownFrownFrown
-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 14, 2009, 11:00 AM)


Edit Log:
Post edited by vikas.deep (User) on May 14, 2009, 11:00 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