aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}