Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Creating 2 arrays from a larger array

by imtakinbioinformatic (Initiate)
on Mar 08, 2012 at 03:18 UTC ( #958416=note: print w/ replies, xml ) Need Help??


in reply to Re: Creating 2 arrays from a larger array
in thread Creating 2 arrays from a larger array

Thanks tangent! I'm confused how  push (@sequences, $dnaString) ever operates. If the string matches >, it goes to the seqList array, so how is the @sequences array being created?


Comment on Re^2: Creating 2 arrays from a larger array
Download Code
Re^3: Creating 2 arrays from a larger array
by tangent (Curate) on Mar 08, 2012 at 03:32 UTC
    You are in a loop, so $dnaString is being added to everytime the line doesn't match your start pattern. $dnaString is always one step behind @seqList so when you come to the next start line, it pushes the previous $dnaString onto @sequences, then clears it for the next iteration. Best thing to do is try it: set $count = 1 and see what happens.

    Update: after re-reading this I'm a bit confused myself. Better to put a print statement within the loop:
    my $dnaString = ''; ... if ($line=~/^>(\S+)/){ print qq|Count: $count, Match: $1, String: $dnaString\n|; push (@seqList, $1);
      uggg still not getting it. No errors but the elements I printed were all the same. I'll keep working, thanks for explaining!
        A HASH makes more sense for this structure:
        my ($k,$v, %seq); for my $line (<DATA>) { chomp ($line); if ( $line=~/^>(\S+)\s*(.*)/){ $k=$1; $v=$2; }else{ $v=$line; } $seq{$k} .= $v; } #---- Print it ---- for my $k(sort keys %seq){ print "$k \t=> $seq{$k}\n"; } # --- Output ---(Using the __DATA__ block above) ..- # 123 => blahabcdefghijkl # 456 => de dahmnopqr # 789 => nothing wanted herestuvwxyz

                     All great truths begin as blasphemies.
                           ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

        but the elements I printed were all the same
        Can you post some sample data?
        Oh it works! It seemed important that the variables were my variables? Thank you soooo much!!
      Yeah here's the file http://www.med.nyu.edu/rcr/rcr/course/smutans.fas

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-20 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (99 votes), past polls