[Bioperl-l] problem with bioperl code- How to create a hash

vikas.deep deep.vik at gmail.com
Thu May 14 14:06:02 EDT 2009


Some one Kindly help me I am a novice programmer
I am trying to create a hash using the code as follows
#! /usr/bin/perl -w
use Bio::DB::GenBank;
use strict;
use Bio::Seq;
use Bio::SeqIO;
use Bio::DB::SwissProt;
{my @key;
my @value;
my @arr;
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 values %h;
In the output 
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!! 
And $h{$key} always says
#[root at localhost Documents]# perl bp.pl
#Use of uninitialized value in print at bp.pl line 46, <$FHHH> line 4.
At the very basic level the problem is to create a hash using 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. 
 I do not know why this is not working. Please Help:-((
-- 
View this message in context: http://www.nabble.com/problem-with-bioperl-code--How-to-create-a-hash-tp23545942p23545942.html
Sent from the Perl - Bioperl-L mailing list archive at Nabble.com.




More information about the Bioperl-l mailing list