... why the + after the first set of parens?

Because I made a mistake and didn't notice because I was getting the right results. It is redundant and removing it makes no difference--'cept maybe it'll run a insy winsy bit quicker? :)

There is a second 'artifact' in the replacement. ($1||'') can become just $1.

I was attempting to avoid the need to suppress warnings, but it turns the code it a mess of bracketed ||s and ternaries; or a long if then else chain. Warnings are optional and turning them off, as an informed decision to avoid complicated code, is (IMO) legit. So I chose the cleaner option. You can replace local $^W; with no warnings 'uninitialised'; or the chain of defined and length tests if you prefer.

Does this explain it?

#! perl -slw use strict; while( <DATA> ) { chomp; printf "Before '%s' becomes ", $_; s[ ( \d+ ) ## Grab any digits before a decimal point (?: \. ## If there is a decimal point ( \d{0,2} ) ## Try grab two digits after it ( \d* ) ## And any more into another capture )? ## All conditionally % ## And finally... ]{ local $^W; ## I know some of the captures will be emp +ty. ## Pad (trailing zeros) the digits being moved to ensure exact +ly 2 my $n = substr( $2 . '00', 0, 2 ); ## Reassemble the number from ## Any digits previously before the decimal point ## The two digits being moved ## A decimal point and the remaining digits if there are +any. $1 . $n . ( length($3) ? ".$3" : '' ); }xe; print "'$_'"; } __DATA__

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Maintain accuracy of floating point numbers in simple arithmetic operation by BrowserUk
in thread Maintain accuracy of floating point numbers in simple arithmetic operation by OfficeLinebacker

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.