I probably shouldn't be responding because I don't fully understand tybalt89's code. I think I understand part of it, but not sure I understand it well enough to try to explain to anyone.

In looking at the my $leftside line, I tried working my way from inside out.

For the |., I found the documentation for Bitwise String Operators. It looks like the combination of use feature 'bitwise' and |. means that bitwise string OR operation was used. I don't fully understand bitwise string OR, but from that documentation it looks like the result is a string that has the same length as the longer of the two strings used in the operation. And in tybalt89's code, the resulting string is not important - only the length of it is important.

The next level is the reduce function. I think I get the gist of what's happening, but not sure that I can explain it well. In the code, @floats is an AoA structure. I think that the reduce function here is being used with the bitwise string OR operator to find the longest length string of the first element of the second level array. (By second level array, I am referring to the level that has 'valid" and 'invalid' strings as the second element.

After the reduce function does its work, then the length of the final resulting string is assigned to the $leftside variable. In the printf statement, the $leftside variable is used to create a right-justified 'field' where the $str variable (the first element of the second level of the @floats AoA data) is printed.

I admit that I'm getting lost with the regex due to my low level skill/knowledge with regexes. Treating that as a black box and looking at the inputs and outputs, it seems like the regex is pulling out valid float number values from the $str variable to put into the @numbers array, which in turn is used in the printf statement.

I probably didn't accurately describe things, but I tried to explain what I think I understand about tybalt89's code. Not sure if it helps you to gain a better understanding of the code or not.


In reply to Re^3: Best practice validating numerics with regex? by dasgar
in thread Best practice validating numerics with regex? by perlboy_emeritus

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.