in reply to Quality trimming of fastq file
I strongly agree with Cristoforo's advice to avoid modifying the size of an array over which one is iterating; see Foreach Loops:
If any part of LIST is an array, "foreach" will get very confused if you add or remove elements within the loop body, for example with "splice". So don't do that.My advice to anyone who describes him- or herself as "... studying for the first time in my life ... Perl ..." is to shun such an unclean practice.
I don't understand the nature and structure of the data in the array being processed by the two foreach-loops in question. If you could describe this data and what you are trying to achieve (with input-data and output-data examples), perhaps we could suggest a more straightforward (and safer!) way to accomplish the same end. See Short, Self-Contained, Correct Example.
Update: I wonder if you are aware that foreach iterates over a list (which may contain one or more arrays or consist entirely in an array) from lowest to highest list item index, while pop removes the highest index element from an array? The two foreach-loops in question are testing elements in an array from low to high and removing the highest elements.
c:\@Work\Perl\monks>perl -wMstrict -le "my @ra = 1 .. 9; foreach my $element (@ra) { printf qq{<$element> }; } print qq{\n}; ;; pop @ra; ;; foreach my $element (@ra) { printf qq{<$element> }; } print qq{\n}; " <1> <2> <3> <4> <5> <6> <7> <8> <9> <1> <2> <3> <4> <5> <6> <7> <8>
Give a man a fish: <%-{-{-{-<
|
|---|