From 87f2cca1c08b724332092b0ab73fcd522247af53 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 25 Jan 2021 15:36:23 +0000 Subject: added some comments --- challenge-097/james-smith/perl/ch-2.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/challenge-097/james-smith/perl/ch-2.pl b/challenge-097/james-smith/perl/ch-2.pl index a995d64d5c..805b834d72 100644 --- a/challenge-097/james-smith/perl/ch-2.pl +++ b/challenge-097/james-smith/perl/ch-2.pl @@ -17,11 +17,19 @@ done_testing(); sub min_flips { ## Golf mode on... + ## + ## This was to use this to serve as an example of perl idioms that other programmers + ## may find it difficult to understand - and so I tried to put as many of them in relatively + ## short function.... + ## + ## One statement functions are a lovely perl concept - even if they can get a bit difficult + ## to read.... + ## return [ map { local $/ = - local $\ = ( $_[0] ^ ( substr $_[0], $_, $_[1]) x (length($_[0])/$_[1]) ) =~ tr/\x01/\x01/, - !$_ || $_ < $/ ? $\ : $/, - } + local $\ = ( $_[0] ^ ( substr $_[0], $_, $_[1]) x (length($_[0])/$_[1]) ) =~ tr/\x01/\x01/, + !$_ || $_ < $/ ? $\ : $/, + } map { $_*$_[1] } 0 .. ( length($_[0])/$_[1] - 1 ) ]->[-1]; -- cgit