| Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Parse/Number/EN.pm |
| Statements | Executed 14 statements in 1.22ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 924µs | 936µs | Parse::Number::EN::BEGIN@12 |
| 1 | 1 | 1 | 36µs | 36µs | Parse::Number::EN::BEGIN@8 |
| 1 | 1 | 1 | 11µs | 15µs | Parse::Number::EN::BEGIN@9 |
| 1 | 1 | 1 | 10µs | 17µs | Parse::Number::EN::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | Parse::Number::EN::parse_number_en |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Parse::Number::EN; | ||||
| 2 | |||||
| 3 | 1 | 500ns | our $DATE = '2016-06-14'; # DATE | ||
| 4 | 1 | 200ns | our $VERSION = '0.07'; # VERSION | ||
| 5 | |||||
| 6 | # TODO: make it OO and customize thousand sep & decimal point | ||||
| 7 | |||||
| 8 | 2 | 63µs | 1 | 36µs | # spent 36µs within Parse::Number::EN::BEGIN@8 which was called:
# once (36µs+0s) by DateTime::Format::Alami::EN::BEGIN@14 at line 8 # spent 36µs making 1 call to Parse::Number::EN::BEGIN@8 |
| 9 | 2 | 30µs | 2 | 20µs | # spent 15µs (11+5) within Parse::Number::EN::BEGIN@9 which was called:
# once (11µs+5µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 9 # spent 15µs making 1 call to Parse::Number::EN::BEGIN@9
# spent 5µs making 1 call to strict::import |
| 10 | 2 | 31µs | 2 | 24µs | # spent 17µs (10+7) within Parse::Number::EN::BEGIN@10 which was called:
# once (10µs+7µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 10 # spent 17µs making 1 call to Parse::Number::EN::BEGIN@10
# spent 7µs making 1 call to warnings::import |
| 11 | |||||
| 12 | 2 | 1.08ms | 2 | 948µs | # spent 936µs (924+12) within Parse::Number::EN::BEGIN@12 which was called:
# once (924µs+12µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 12 # spent 936µs making 1 call to Parse::Number::EN::BEGIN@12
# spent 12µs making 1 call to Exporter::import |
| 13 | 1 | 1µs | our @EXPORT_OK = qw($Pat parse_number_en); | ||
| 14 | |||||
| 15 | our %SPEC; | ||||
| 16 | |||||
| 17 | #our $Pat = qr/(?: | ||||
| 18 | # [+-]? | ||||
| 19 | # (?: | ||||
| 20 | # (?:\d{1,3}(?:[,]\d{3})+ | \d+) (?:[.]\d*)? | # english | ||||
| 21 | # [.]\d+ | ||||
| 22 | # ) | ||||
| 23 | # (?:[Ee][+-]?\d+)? | ||||
| 24 | # )/x; | ||||
| 25 | |||||
| 26 | # non /x version | ||||
| 27 | 1 | 100ns | our $Pat = '(?:[+-]?(?:(?:\d{1,3}(?:[,]\d{3})+|\d+)(?:[.]\d*)?|[.]\d+)(?:[Ee][+-]?\d+)?)'; | ||
| 28 | |||||
| 29 | $SPEC{parse_number_en} = { | ||||
| 30 | 1 | 5µs | v => 1.1, | ||
| 31 | summary => 'Parse number from English text', | ||||
| 32 | description => <<'_', | ||||
| 33 | |||||
| 34 | This function can parse number with thousand separators (e.g. 10,000). | ||||
| 35 | |||||
| 36 | In the future percentage (e.g. 10.2%) and fractions (e.g. 1/3, 2 1/2) might also | ||||
| 37 | be supported. | ||||
| 38 | |||||
| 39 | _ | ||||
| 40 | args => { | ||||
| 41 | text => { | ||||
| 42 | summary => 'The input text that contains number', | ||||
| 43 | schema => 'str*', | ||||
| 44 | req => 1, | ||||
| 45 | pos => 0, | ||||
| 46 | }, | ||||
| 47 | }, | ||||
| 48 | result_naked => 1, | ||||
| 49 | }; | ||||
| 50 | sub parse_number_en { | ||||
| 51 | my %args = @_; | ||||
| 52 | my $text = $args{text}; | ||||
| 53 | |||||
| 54 | return undef unless $text =~ s/^\s*($Pat)//s; | ||||
| 55 | my $n = $1; | ||||
| 56 | $n =~ s/,//g; | ||||
| 57 | $n+0; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | 1 | 7µs | 1; | ||
| 61 | # ABSTRACT: Parse number from English text | ||||
| 62 | |||||
| 63 | __END__ |