Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: splitting data advice requested

by johngg (Canon)
on May 13, 2009 at 15:45 UTC ( [id://763804]=note: print w/replies, xml ) Need Help??


in reply to Re: splitting data advice requested
in thread splitting data advice requested

Another way of getting rid of the newlines would be to lose all of them with the second split, passing the fields out in an anonymous array, and then map out the key and sequence using shift and join.

use strict; use warnings; use Data::Dumper; my %hash = map { ( shift @$_, join q{}, @$_ ) } map { [ split m{\n} ] } map { split m{\n(?=>)} } do { local $/; <DATA> }; print Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] ); __DATA__ >SEQ1 -----I--RL--AAIDVDG-NLT----------D--R--D-RL-ISTKA-IESIRS--A- -E-K--------K-GLT-VSL----LS------GN-V----I-PVV---YA-L------K IF---------------L-----GINGPVF------------------------------ >SEQ2 -MKI----KA--ISIDIDG-TIT------YPN-R-------MIHEK--A-LEAIRR--A- -E-S--------L-GIP-IML----VT------GN-T----V-QFA---EA-A------S IL---------------I-----G----TS-----------------GP-VV-------- >SEQ3 --KI----KA--ISIDIDG-TIT------YPN-R-------MIHEK--A-LEAIRR--A- -E-S--------L-GIP-IML----VT------GN-T----V-QFA---EA-A------S IL---------------I-----G----TS-----------------GP-VV-------- ---AE--D------GG---A---------------------------------------I

The output.

%hash = ( '>SEQ1' => '-----I--RL--AAIDVDG-NLT----------D--R--D-RL-ISTK +A-IESIRS--A--E-K--------K-GLT-VSL----LS------GN-V----I-PVV---YA-L---- +--KIF---------------L-----GINGPVF------------------------------', '>SEQ3' => '--KI----KA--ISIDIDG-TIT------YPN-R-------MIHEK-- +A-LEAIRR--A--E-S--------L-GIP-IML----VT------GN-T----V-QFA---EA-A---- +--SIL---------------I-----G----TS-----------------GP-VV-----------AE- +-D------GG---A---------------------------------------I', '>SEQ2' => '-MKI----KA--ISIDIDG-TIT------YPN-R-------MIHEK-- +A-LEAIRR--A--E-S--------L-GIP-IML----VT------GN-T----V-QFA---EA-A---- +--SIL---------------I-----G----TS-----------------GP-VV--------' );

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found