perlancar

NAME

Parse::Number::EN - Parse number from English text

VERSION

This document describes version 0.07 of Parse::Number::EN (from Perl distribution Parse-Number-EN), released on 2016-06-14.

SYNOPSIS

 use Parse::Number::EN qw(parse_number_en $Pat);

 my @a = map {parse_number_en(text=>$_)}
     ("12,345.67", "-1.2e3", "x123", "1.23", "1,23");
 # @a = (12345.67, -1200, undef, 1.23, 1)

 my @b = map {/^$Pat$/ ? 1:0}
     ("12,345.67", "-1.2e3", "x123", "1,23");
 # @b = (1, 1, 0, 0)

DESCRIPTION

The goal for this module is to parse/extract numbers written in some common notation in English text. That means, in addition to what Perl does, it also recognizes thousand separators (and fractions, percentages in the future).

VARIABLES

None are exported by default, but they are exportable.

$Pat (REGEX)

A regex for quickly matching/extracting number from text. It's not 100% perfect (the extracted number might not be valid), but it's simple and fast.

FUNCTIONS

parse_number_en(%args) -> any

Parse number from English text.

This function can parse number with thousand separators (e.g. 10,000).

In the future percentage (e.g. 10.2%) and fractions (e.g. 1/3, 2 1/2) might also be supported.

This function is not exported by default, but exportable.

Arguments ('*' denotes required arguments):

  • text* => str

    The input text that contains number.

Return value: (any)

FAQ

How does this module differ from other number-parsing modules?

This module uses a single regex and provides the regex for you to use. Other modules might be more accurate and/or faster. But this module is pretty fast.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Parse-Number-EN.

SOURCE

Source repository is at https://github.com/perlancar/perl-Parse-Number-EN.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-Number-EN

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Lingua::EN::Words2Nums

Other Parse::Number::* modules (for other languages).

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.