http://qs1969.pair.com?node_id=627111

You have a temp that is assigned once with a simple expression, and the temp is getting in the way of other refactorings.

Replace all references to that temp with the expression.

(Fowler, p. 119)

Inline Temp is probably the most trivial refactoring pattern:

my $base_price = $self->an_order->base_price(); return ( $base_price > 1000 );

becomes:

return ( $self->an_order->base_price() > 1000 );

Get the code

This causes occasional consternation in code reviews I attend, as some like to create temp variables to clarify their code and other find it to be unnecessary clutter. I find that programmers most often employ this technique when a verbose method name or deep data structure would otherwise exist multiple times in code:

my $thing = $that_object->that_method->{thing}; $obj->do_this_with( $thing ); $obj->do_that_with( $thing );

I generally avoid getting into scuff-ups about such matters. Fowler suggests this refactoring for situations where the temp gets in the way of other refactoring, generally Replace Temp With Query (up next).

Fowler also suggests an interesting technique to aid in the refactoring:

Declare the temp as final if it isn't already and compile. This checks that the tem is really only assigned to once. (Fowler, p. 119)

While Perl lacks the means to turn a once dynamic variable into a read-only (does anyone know of one?) there are a number of ways to create read only variables in perl. My favorite is Readonly. This is a debugging technique that I hadn't considered before.

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));'