diff options
| author | Dimitar Dimitrov <mitkofr@yahoo.fr> | 2021-05-13 10:48:02 +0100 |
|---|---|---|
| committer | Dimitar Dimitrov <mitkofr@yahoo.fr> | 2021-05-13 10:48:02 +0100 |
| commit | d7579fae3c96c131c5e589291c31418b215e792c (patch) | |
| tree | 3aed0f775559ceab946ff70204c06d53afb63bf9 | |
| parent | e0502c74dfd41988164c284290e86afca6d8c6ad (diff) | |
| download | perlweeklychallenge-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.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..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; |
