in reply to Uninitialized value in substr command
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Uninitialized value in substr command
by Lotus1 (Vicar) on Aug 21, 2014 at 14:06 UTC | |
|
Re^2: Uninitialized value in substr command
by lmtaylor (Novice) on Aug 21, 2014 at 17:44 UTC |