Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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

Replies are listed 'Best First'.
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?
LanX wonders, do we have a rule against systematic down voting?
[erix]: we frown :)
[marto]: Does the command line arg --product-version@ help?
[LanX]: xD
[erix]: 'systematic' is going to be hard to define I think
[marto]: Err no @
LanX Much enemy much ore
[Corion]: marto: Naah, my module doesn't care, but the users of my module might expect some things to work in Chrome that only work in later builds (or, as seems to be the case, don't work there either ;) )

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-12-12 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?