in reply to Re^4: Handling HUGE amounts of data
in thread Handling HUGE amounts of data

I figure that returning a single variable ($zaza)is more efficient than returning $aob$x$y

Returning $aob[$x][$y], is returning a single variable. Whether you derefence the arrays here:

$zaza = $aob[$x][$y];

Or here:

return $aob[$x][$y];

Makes no difference.

However, using my for ( $x, $y, $z ) & $zaza would make some difference as lexicals are more efficient than globals. Plus you could then benefit from use strict.

But your subroutine can be refactored as:

sub popnum1 { my( $x, $y, $z ) = @_; if ( $y == 0 ) { return $aob[$x][0] = $initial + $z; } else { if ( substr( $aod[ $y - 1 ], $x, 1 ) ne 'a' ) { return $aob[$x][$y] = $initial + $z; } else { return $aob[$x][$y] = $z + $aob[$x][ $y - 1 ]; } } }

which saves a temporary variable and two, double dereferences.

Personally, I think I'd code that as:

sub popnum1 { my( $x, $y, $z ) = @_; return $aob[ $x ][ $y ] = $y && substr( $aod[ $y - 1 ], $x, 1 ) ne 'a' ? $initial + $z : $z + $aob[$x][ $y - 1 ]; }

Though I'd want to verify that my logic transformation was correct. That should be appreciably more efficient than your original above.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: Handling HUGE amounts of data
by Dandello (Monk) on Jan 31, 2011 at 20:49 UTC

    Actually I am using strict - the my declaration for $x, $y, and $z was elsewhere. And this was my original before I got creative:

    sub popnum1 { ( $x, $y, $z ) = @_; if ( $y == 0 ) { $aob[$x][0] = $initial + $z; } else { if ( substr( $aod[ $y - 1 ], $x, 1 ) ne 'a' ) { $aob[$x][$y] = $initial + $z; } else { $aob[$x][$y] = $z + $aob[$x][ $y - 1 ]; } } return $aob[$x][$y]; }

    I've moved the Perl/Tk done snippet into a different script and running the full load still throws an 'out of memory' during what should be cleanup. Now I have to track down exactly where.

      Actually I am using strict - the my declaration for $x, $y, and $z was elsewhere.

      Well that's just silly.

      Now I have to track down exactly where.

      If you scoped your variables properly, it might make that task easier.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        A little sleuthing indicates it's not a problem with scoping the variables. But I'm still digging.

        The script is throwing the 'out of memory' after the output file is closed, after that entire subroutine has returned to main.

        In fact, it's throwing the 'out of memory after dataout.pl has called the next script in the chain.

        That would indicate it's throwing 'out of memory' during clean-up somewhere, right?

        Or maybe it's doing it because it's on Windows.