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.
In reply to Re^5: Handling HUGE amounts of data
by BrowserUk
in thread Handling HUGE amounts of data
by Dandello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |