If I correctly understand what is happening here, the letter 'D' is a locale-specific exponentiation letter: what locale are you using? Since the output shows that perl is parsing the number correctly, I'd guess that the "Argument isn't numeric" warning is a bug in perl - that it is checking only for "E" as the exponentiation letter - but that the operating system library is then correctly converting the number.
If that is correct, the best workaround I can think of is to locally disable the warning, and check the correctness yourself:
sub weird2number { my $text = shift; unless ($text =~ /^\d*\.\d+D[+\-]\d+$/) { warn qq{Argument "$text" is not weird}; } no warnings "numeric"; return $text + 0; }
If you also need to output numbers in this format, you may also have problems: the closest is the (s)printf '%E' format, which puts the first significant digit before the decimal point. The simplest way I can think of to get around that is to use sprintf '%E', $number and then modify the result, perhaps like so:
sub number2weird { my $number = shift; my $text = sprintf '%.14E', $number; $text =~ s{ (\d) \. (\d+ [DE]) ([+\-] \d+) }{ "0.$1$2" . sprintf "%+03d", $3 + 1 }xe or warn qq{Failed to make "$text" weird}; return $text; }
Note however that the output format of sprintf '%E' is also dependent on your operating system libraries, so you may need to modify the pattern to match correctly.
HugoIn reply to Re: Weird number formatting
by hv
in thread Weird number formatting
by licking9Volts
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |