imtakinbioinformatic has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have a question that hopefully is pretty simple. Below I am creating an array of headers, but I want to make an array that only keeps the 1st word of each element. (Each element in the array starts with a > because they are different contigs.) I tried both ways that are commented out below, but I'm just getting an empty array with both of them. Tips? Thanks!
foreach $line(@DNA) { # if ($line =~/^>(\w+)\s(.+)$/) { if($line =~/^>/){ push(@seqnames, $line); #@firstword = grep(/^>(\w+)\s(.+)/,@segnames); } else {push(@sequences, $line);} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep 1st word of strings in array
by NetWallah (Canon) on Mar 07, 2012 at 15:31 UTC | |
|
Re: Grep 1st word of strings in array
by aaron_baugher (Curate) on Mar 07, 2012 at 22:27 UTC | |
by Marshall (Canon) on Mar 08, 2012 at 00:03 UTC | |
|
Re: Grep 1st word of strings in array
by kcott (Archbishop) on Mar 07, 2012 at 15:08 UTC | |
by Marshall (Canon) on Mar 07, 2012 at 17:32 UTC | |
by kcott (Archbishop) on Mar 07, 2012 at 18:00 UTC | |
|
Re: Grep 1st word of strings in array
by Marshall (Canon) on Mar 07, 2012 at 17:09 UTC | |
|
Re: Grep 1st word of strings in array
by tobyink (Canon) on Mar 09, 2012 at 11:33 UTC |