Kian-Meng Ang Weekly Review: Challenge - 021

Sunday, Aug 25, 2019| Tags: Perl

Continues from previous week.

Feel free to submit a merge request or open a ticket if you found any issues with this post. We highly appreciate and welcome your feedback.

For a quick overview, go through the original tasks and recap of the weekly challenge.

Task #1

CPAN modules used: bignum, Carp, Const::Fast, Getopt::Long, Math::AnyNum, Math::Big, Math::BigFloat, Math::Big, Math::BigRat, Math::NumberCruncher, Math::Symbolic, Modern::Perl, Sidef, Test::More and Text::Table::Tiny.

The biggest takeaway for this task was the solution by Randy Lauen where he did a comparison of different CPAN modules against the formulated calculation. Perl is known for its TIMTOWTDI motto, but after so many weekly challenges, we can safely say, there’s more than one CPAN module to use it. Checking against the recommended CPAN module list, Task::Kensho, none was listed there and we can’t seem to find anything mathematical related CPAN modules as well. Nothing was found from kablamo‘s recommended list as well.

| Module                       | Euler's Number                                      |
| Math::Big::euler             | 2.7182818284590452353602874713526624977572470937    |
| Math::NumberCruncher::ECONST | 2.7182818284590452353602874713526624977572470937    |
| Math::NumberCruncher::_e_    | 2.7182818284590452353602874713526624977572470936... |
| Math::Symbolic::EULER        | 2.71828182845905                                    |
| Math::AnyNum::euler          | 2.7182818284590452353602874713526624977572470937    |
| Sidef Number.e               | 2.7182818284590452353602874713526624977572470937    |
| bigrat::e                    | 2.718281828459045235360287471352662497757           |
| Calculated e                 | 2.7182818284590452353602874713526625112110646491... |

Task #2

CPAN modules used: Carp, Data::Dumper, Function::Parameters, Modern::Perl, Parse::RecDescent, Test::More, URI, URI::Escape, URI, URI::Normalize, URI::URL, URL::Normalize and Parse::Yapp.

Solutions can be grouped into two ways, either reinvent the wheel or use existing CPAN modules. Daniel Mantovani picked the later approach as there were too many edge cases. He had learned that URL::Normalize was “heavier” (external dependencies) compares to URI::Normalize but allows more customization. Lubos Kolouch also picked the same approach and CPAN module. Likewise for E. Choroba, Adam Russell, Duane Powell, and Dave Cross but using different CPAN modules.

Ruben Westerberg, Guillermo Ramos, Laurent Rosenfeld, Jaldhar H. Vyas, Duncan C White, Roger Bell West and Andrezgz, belongs to the camp that solved it just by using regex without external CPAN modules. URL normalization is a tedious process and there are many steps involved in parsing, normalizing, and reassembling. See the code snippet of Jaldhar‘s solution shown below for the possible steps involved.

  say reassemble(

Notable submissions by Joelle Maslak and Adam Russell which used Parse::RecDescent and Parse::Yapp CPAN module to generate their own URL parser to normalize a URL.

Task #3

CPAN modules used: autodie, Getopt::Long, HTTP::API::Client, Mojo::UserAgent, Mojo::Util, Path::Tiny and Perl6::Slurp.

Both Randy Lauen and Joelle Maslak were the only participants to Perl 5 and Perl 6 solutions. While Joelle preferred Mojo::UserAgent, Randy opted for HTTP::API::Client, a lightweight HTTP client CPAN module that was based on either LWP::UserAgent or Net::Curl::Simple with built-in support for parsing JSON result. As usual, for those who haven’t done this task before, do give it a try.

See Also

(1) Euler’s URL with Perl 6 by Arne Sommer

(2) Implementing a spigot algorithm for the digits of e by Adam Russell

(3) PWC Week 21 - Euler’s Constant and Big Numbers by Dave Jacoby

(4) Perl Weekly Challenge # 21: Euler’s Number and URL Normalizing by Laurent Rosenfeld

(5) Perl Weekly Challenge: Week 21 by Jaldhar H. Vyas

(6) RogerBW’s Blog: Perl Weekly Challenge 21 by Roger Bell West


If you have any suggestions or ideas then please do share with us.

Contact with me