in reply to Re^2: Refactoring Perl 4 - Replace Temp with Query
in thread Refactoring Perl #4 - Replace Temp with Query

Won't work if $self->{_item_price} changes.

Of course abstracting such things away is the right way to go; but you still often need temp variables. So this refactoring technique should probably be promoted as "do what common sense tells you", not as "remove temp vars".

Memoize is a good thing too, btw. Even better with Memoize::Attrs.

Replies are listed 'Best First'.
Re^4: Refactoring Perl 4 - Replace Temp with Query
by agianni (Hermit) on Jul 30, 2007 at 12:48 UTC

    Right, up till now, I haven't had to do anything but the simplest forms of Memoization, so my example would generally work for me. I find myself doing memoization most often when I'm doing database queries that I expect should return the same things for the duration of the process, i.e. if handling a Web request. Obviously the situation would be different if one were running a persistent process.

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'