aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitar Dimitrov <mitkofr@yahoo.fr>2021-05-13 10:48:02 +0100
committerDimitar Dimitrov <mitkofr@yahoo.fr>2021-05-13 10:48:02 +0100
commitd7579fae3c96c131c5e589291c31418b215e792c (patch)
tree3aed0f775559ceab946ff70204c06d53afb63bf9
parente0502c74dfd41988164c284290e86afca6d8c6ad (diff)
downloadperlweeklychallenge-club-d7579fae3c96c131c5e589291c31418b215e792c.tar.gz
perlweeklychallenge-club-d7579fae3c96c131c5e589291c31418b215e792c.tar.bz2
perlweeklychallenge-club-d7579fae3c96c131c5e589291c31418b215e792c.zip
Add human readable version
-rw-r--r--challenge-112/kurkale6ka/perl/ch-1.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-112/kurkale6ka/perl/ch-1.pl b/challenge-112/kurkale6ka/perl/ch-1.pl
index 9e5d37f74d..c94eb15658 100644
--- a/challenge-112/kurkale6ka/perl/ch-1.pl
+++ b/challenge-112/kurkale6ka/perl/ch-1.pl
@@ -19,3 +19,25 @@ s#/\.?(?=(/|$))##gn;
# { redo if s#/([^/]+/)?\Q..##n }
say $_||'/'
+
+__DATA__
+
+Human readable version without regexes
+
+# one-liner:
+# -E'for(split/\//,pop){/^\.$/&&next;if(/^\.\.$/){pop@path}else{push@path,$_ if length}}say"/",join"/",@path'
+
+my @path;
+
+foreach (split m#/#, shift)
+{
+ next if $_ eq '.';
+
+ if ($_ eq '..') {
+ pop @path;
+ } else {
+ push @path, $_ if length;
+ }
+}
+
+say '/', join '/', @path;