Kian-Meng Ang Weekly Review: Challenge - 027

Sunday, Oct 6, 2019| Tags: Perl5

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: Function::Parameters, Getopt::Long, List::Util, Modern::Perl, Moose, Regexp::Common, Test::Exception, Test::More, feature, strict, utf8, warnings

Start with the submission by Duncan C White. His solution was the only one with visualization through Gnuplot. For those who want to try it out, you can test using the sample command below. While the plot was a good way look at the intersection graphically (alternatively, read the blog post by Arne Sommer), it doesn’t handle all test data correctly, especially the test cases from E. Choroba.

$ perl 1 4 4 2 2 4 1
a=1, b=4, c=4, d=2, p=2, q=4, r=1, s=1
line 1 : y = -0.666666666666667 x + 4.66666666666667
line 2 : y = 3 x + -2
intersection at (1.81818181818182,3.45454545454546)
show results in gnuplot? y

Next, study the solution by Joelle Maslak which was very comprehensive. The solution demonstrated different features of Perl 5 like method signatures, Unicode support, Object-oriented programming through Moose, and well-written comment explaining the solution.

For this task, the participant needs to handle many command line arguments and we’ve observed different ways of doing it in Perl. The common approach was just expanding these command line arguments into argument list as seen in the solution by Duane Powell, Laurent Rosenfeld, Roger Bell_West (using shift), Lubos Kolouch, and Joelle Maslak. Or if you prefer array slicing as used by Adam Russell, Yet Ebreo and Duncan C White

Special mention of Andrezgz, which provides us with clear instruction on how to pass arguments to its console app. Likewise for Colin Crain which have far more complex but tasteful way to handle co-ordinates as well as validation.

Task #2

CPAN modules used: Class::Hash, Data::Dump, Data::Dumper, Filter::Simple, Function::Parameters, Modern::Perl, Moo, Moose, Storable, Test::More, Tie::Scalar, Variable::Magic, feature, lib, parent, strict, warnings

This was one of those task where participants really demonstrated different Perl features or CPAN modules to solve a problem.

Start with the solution by Duane Powell as we learned about basic OO usage in Perl without any external CPAN modules dependencies. Follow this by the solution by Colin Crain and Joelle Maslak. Both share some similarities but using external dependencies and conventional naming conventions.

The typical approach was to use the Tie::Scalar CPAN module. Participants who took this approach were Mark Anderson, Ruben Westerberg and E. Choroba (very compact and clean solution).

And then there were those who’ve chosen to implement something similar using tie but without using the Tie::Scalar CPAN module. Trenton Langer, Yet Ebreo and Joelle Maslak were the three participants who experimented with such method.

And Roger Bell_West solved this solution with magic, other to be precise, Variable::Magic, a special CPAN module that let you add your own magic to any variable.

These were the participants that preferred unorthodox aproaches.

Laurent Rosenfeld used a simple yet powerful programming language feature, Closure in Perl to implement logging. This was also a good approach as Closure allows us to keep track of variables that gone out of the scope.

While Lubos Kolouch and Andrezgz have an interesting interpretation and literally solved the problem as it is using eval.

Again, Duncan C White solved this problem by providing a visualization through Gnuplot by implementing a simple numerical logging by operator.

Lastly, the participant that always willing to try and explore different approach, Adam Russell took it to another level by logging through source filter. Read his blog post on how he implemented this.


(1) Historical Intersection with Perl 6 by Arne Sommer

(2) Perl Weekly Challenge 027 by Adam Russell

(3) Perl Weekly Challenge 27: Intersection Point and Historical Values by Laurent Rosenfeld

(4) RogerBW’s Blog: Perl Weekly Challenge 27 by Roger Bell_West

(5) Perl Weekly Challenge 027: Intersection of Straight Lines and Historical Data by E. Choroba


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

Contact with me