If you have a file, you should probably avoid using a temporary array (at least if you file is big), but rather do essentially the same thing directly in a while loop reading the file:my $string = ""; my @new_array; for my $item (@contigfile) { if ( $item =~ /^>\d) { push @new_array, $string unless $string eq ""; $string = ""; } else { $string .= $item; } } push @new_array, $string; # takes care of the last element
Update: fixed the typo indicated by Lotus1 (in the post just below) in the regex (I had inadvertently forgotten the '>'). Thanks to Lotus1.my $string = ""; while (my $line = <$input_fh>) { chomp $line; if ( $line =~ /^>\d) { push @new_array, $string unless $string eq "";; $string = ""; } else { $string .= $line; } } push @new_array, $string; # take care of the last element
In reply to Re: Uninitialized value in substr command
by Laurent_R
in thread Uninitialized value in substr command
by lmtaylor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |