in reply to Help with pushing into a hash
I have assumed that the stray space at the first line of your first file is just a typo.use Modern::Perl; use Data::Dump qw/dump/; my %acn_database; while (<DATA>) { last if /END/; my ($acn, $orfname) = split /\sORFNames=|\s/; $acn_database{$acn} = [$orfname]; } while (<DATA>) { my ($acn, @pf_data) = split /\s\|\s|\s/; push @{$acn_database{$acn}}, @pf_data; } say dump(\%acn_database); __DATA__ Q197F8 ORFNames=IIV3-002R Q197F7 ORFNames=IIV3-003L Q6GZX2 ORFNames=FV3-003R Q6GZX1 ORFNames=FV3-004R Q197F5 ORFNames=IIV3-005L Q6GZX0 ORFNames=FV3-005R ;PF02393 Q91G88 ORFNames=IIV6-006L ;PF12299;PF04383 Q6GZW9 ORFNames=FV3-006R END Q197F8 | PF04947.9 Q91G88 | PF01486.12 PF00319.13
Note that this will still do the right thing if you have multiple lines in your second file with the same accession numbers: their data will just be added to right array in the hash.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|