I certainly don't advocate for refactoring or following any particular guru advice merely for the sake of doing so. You are absolutely right that this example may appear unnecessary or counterproductive. If you found this to be the case in a particular example you ran into in the real world, I would expect that you would not choose to refactor.

Fowler discusses the upsides and downsides of refactoring in the early chapters of the book. If you find yourself interested in the details then, by all means, pick up a copy. Otherwise, please take these examples with a grain of salt.

This example may not be so good in part because it lacks context. As I mentioned in the OP, something like value of the $base_price temp variable is likely to be used in a number of different places in your code. As such, refactoring the definition of the base price actually limits rather than raises the potential for introduction of bugs by defining what base price means in one place. Again, context is the key, and the lack of context in some of these examples will undoubtedly cause confusion at times.

The upshot is that my goal here is to start with Fowler's examples and work from them. There will undoubtedly be cases where the examples don't necessarily translate well. This may be, in part, because I am converting examples in Java, where OO isn't a choice, to Perl, where it is. Or, it may be that an example that works well in Java doesn't work so well in Perl, despite the validity of the refactoing pattern. As such, issues like these will likely arise.

I am posting these examples to PerlMonks expressly to encourage discussion. So please don't take this reply (mine) as an admonition for silence. I would simply ask that y'all keep an open mind about it, take the examples with a grain of salt and keep the conversation going. I'm happy to be participating in this conversation about OO techniques in Perl.

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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.