diff options
| -rw-r--r-- | challenge-112/kurkale6ka/perl/ch-1.pl | 22 |
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..db35dea061 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 $_||'/' + +__END__ + +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; |
