in reply to Re^2: Best practice validating numerics with regex?
in thread Best practice validating numerics with regex?

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.