Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Help with pushing into a hash

by CountZero (Bishop)
on Aug 29, 2012 at 19:56 UTC ( #990548=note: print w/ replies, xml ) Need Help??


in reply to Help with pushing into a hash

I did it so:

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
I have assumed that the stray space at the first line of your first file is just a typo.

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


Comment on Re: Help with pushing into a hash
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990548]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-08-27 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls