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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Handling HUGE amounts of data
by Dandello (Monk) on Jan 31, 2011 at 20:49 UTC | |
by BrowserUk (Patriarch) on Jan 31, 2011 at 20:52 UTC | |
by Dandello (Monk) on Jan 31, 2011 at 23:48 UTC | |
by BrowserUk (Patriarch) on Feb 01, 2011 at 00:05 UTC |