Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Perl noob struggling to loop through an array

by jwkrahn (Monsignor)
on Oct 25, 2012 at 03:35 UTC ( #1000756=note: print w/ replies, xml ) Need Help??


in reply to Perl noob struggling to loop through an array

$ echo ">Sequence_Header_A DNAsequence >Sequence_Header_B DNAsequence >Sequence_Header_C DNAsequence" | perl -e' while ( <> ) { next unless /^>/; ( my $format = $_ ) =~ s/\n/_%d\n%s\n/; chomp( my @data = split /(?=e)/, <> ); my $count; printf $format, ++$count, $_ for @data; } ' >Sequence_Header_A_1 DNAs >Sequence_Header_A_2 equ >Sequence_Header_A_3 enc >Sequence_Header_A_4 e >Sequence_Header_B_1 DNAs >Sequence_Header_B_2 equ >Sequence_Header_B_3 enc >Sequence_Header_B_4 e >Sequence_Header_C_1 DNAs >Sequence_Header_C_2 equ >Sequence_Header_C_3 enc >Sequence_Header_C_4 e


Comment on Re: Perl noob struggling to loop through an array
Download Code
Re^2: Perl noob struggling to loop through an array
by microkorg (Initiate) on Oct 26, 2012 at 12:42 UTC
    Thanks for such quick responses aitap and jwkrahn,
    I am happy with the way my code cuts up the data but I am having a more fundamental problem with getting the loop to perform as I wish.

    Could you suggest a way of getting the 2 sections of my own code into a single loop (I realise that jwkrahn suggested a slightly different method, and this is very much appreciated) but I would quite like to get my own technique running smoothly as well.

    Thanks again for all your help.

Re^2: Perl noob struggling to loop through an array
by Anonymous Monk on Oct 26, 2012 at 17:01 UTC
    Hi jwkrahn, would you mind putting some comments into your code explaining each section? I am struggling to follow it through. Thanks, microkorg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-27 06:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls