« blib/lib/Perlmazing/Perlmazing/splitpath.pm
↑ Summary
blib/lib/Perlmazing/Perlmazing/columnize.pm »
| 1 | use Perlmazing qw(is_number to_number croak); | ||
| 2 | our @ISA = qw(Perlmazing::Listable); | ||
| 3 | |||
| 4 | sub main { | ||
| 5 | no warnings; | ||
| 6 | if (not defined $_[0]) { | ||
| 7 | $_[0] = 0; | ||
| 8 | } elsif (is_number $_[0]) { | ||
| 9 | my $copy = $_[0]; | ||
| 10 | # Remove possible _ number separations | ||
| 11 | $copy =~ s/(\d)_(\d)/$1$2/g; | ||
| 12 | # Avoid octal interpretations | ||
| 13 | $copy =~ s/^0+//; | ||
| 14 | my $result = eval "$copy"; | ||
| 15 | croak "Unexpected error with to_number(".dumped($copy)."): $@" if $@; | ||
| 16 | $result = 0 unless defined $result; | ||
| 17 | $_[0] = $result; | ||
| 18 | } else { | ||
| 19 | $_[0] =~ s/\D+//g; | ||
| 20 | $_[0] += 0; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | 1; |