aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-16 18:16:13 +0200
committerAbigail <abigail@abigail.be>2021-05-16 18:16:13 +0200
commitdb15b50ebbaeb24ebe4b4554d26d6175b52966f5 (patch)
tree6f27b178ca366b363b585869e8ed92efd9f2106e
parentb36cd4c90b2457ba4d6e112c0417dfb9891c3cf2 (diff)
downloadperlweeklychallenge-club-db15b50ebbaeb24ebe4b4554d26d6175b52966f5.tar.gz
perlweeklychallenge-club-db15b50ebbaeb24ebe4b4554d26d6175b52966f5.tar.bz2
perlweeklychallenge-club-db15b50ebbaeb24ebe4b4554d26d6175b52966f5.zip
Use same algorithm as other languages
-rw-r--r--challenge-112/abigail/perl/ch-1.pl34
1 files changed, 13 insertions, 21 deletions
diff --git a/challenge-112/abigail/perl/ch-1.pl b/challenge-112/abigail/perl/ch-1.pl
index b68a966191..5d7a0157d5 100644
--- a/challenge-112/abigail/perl/ch-1.pl
+++ b/challenge-112/abigail/perl/ch-1.pl
@@ -19,25 +19,17 @@ use experimental 'lexical_subs';
while (<>) {
chomp;
-
- # Remove duplicate slashes
- s !/\K/+!!g;
-
- # Add a trailing slash; this makes it easier to deal
- # with the cases below.
- $_ .= "/";
-
- # Remove single period
- s !/\.(?=/)!!g;
-
- # Remove double period
- 1 while s !/[^/]+/\.\.(?=/)!!;
-
- # Remove any leading /../
- 1 while s !^/\.\./!/!;
-
- # Remove trailing slashes
- s !/+$!!;
-
- say $_ || '/';
+ my @parts = split /\/+/;
+ my @parts2;
+
+ foreach my $part (@parts) {
+ next if $part eq "." || $part eq "";
+ if ($part eq "..") {
+ pop @parts2;
+ next;
+ }
+ push @parts2 => $part;
+ }
+
+ say "/" . join "/" => @parts2;
}