in reply to Reduce RAM required

Some real low-hanging fruit that should roughly halve your memory requirement:

You accumulate all output in @output and only write it out at the end. Instead, eliminate the variable @output and instead of pushing there, write to the output file directly.

You keep the arrays @IDs, @lengths, @IDsLens and the values in them around for the whole runtime of your program. Insteadd, empty out those arrays as soon as you don't need them anymore. This is usually easiest done by restricting the scope of such variables to be the minimal necessary scope. For example the @IDsLens array is not needed after the assignemtn to the hash.

For futher improvement, instead of building up @IDsLens and then assigning it to the hash, eliminate the variable @IDsLens completely and do the hash assignment in place:

#push @IDsLens, $ID2; #push @IDsLens, $len2; $IDLen_hash{ $ID2 } = length( $ID2 ); ... #my %IDLen_hash = @IDsLens;

You should test whether storing all the lengths in a hash is worth the improvement, compared to directly calculating the length of the string each time, because you only use that hash once to retrieve the length again.

Replies are listed 'Best First'.
Re^2: Reduce RAM required
by onlyIDleft (Scribe) on Jan 09, 2019 at 16:14 UTC

    Thank you! I tried several of these changes, (like undef of several array and scalar variables), but my coding is quite rusty, because I am still getting the modified script to exit with error code 9 on both Mac local machine and UNIX cluster - running out of RAM (I think)

    I have to brush up on Perl coding quite a bit it seems :)