diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-09-12 07:02:42 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-09-12 07:02:42 +0100 |
| commit | e266dcdc46e5640ad62adc8473f73b2eac9a25ec (patch) | |
| tree | 544563f496a1c2b2a4fb2ecf2fb027c35df83537 /challenge-182/james-smith | |
| parent | 41f624e2bd19f232bb4691f8f234e16b1fc3592f (diff) | |
| download | perlweeklychallenge-club-e266dcdc46e5640ad62adc8473f73b2eac9a25ec.tar.gz perlweeklychallenge-club-e266dcdc46e5640ad62adc8473f73b2eac9a25ec.tar.bz2 perlweeklychallenge-club-e266dcdc46e5640ad62adc8473f73b2eac9a25ec.zip | |
minor tweak to cope with relative directory paths (and a belt and braces of directories and filenames "matching")
Diffstat (limited to 'challenge-182/james-smith')
| -rw-r--r-- | challenge-182/james-smith/perl/ch-2.pl | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/challenge-182/james-smith/perl/ch-2.pl b/challenge-182/james-smith/perl/ch-2.pl index 35312ecbe0..74e4512301 100644 --- a/challenge-182/james-smith/perl/ch-2.pl +++ b/challenge-182/james-smith/perl/ch-2.pl @@ -11,6 +11,11 @@ use Data::Dumper qw(Dumper); my @TESTS = ( [ [qw(/a/b/c/1/x.pl /a/b/c/d/e/2/x.pl /a/b/c/d/3/x.pl /a/b/c/4/x.pl /a/b/c/d/5/x.pl)], '/a/b/c' ], [ [qw(/a/b/a.txt /a/b/c/d/e/q.txt /a/b/c.txt)], '/a/b' ], + [ [qw(a/b/a.txt a/b/c/d/e/q.txt a/b/c.txt)], 'a/b' ], + [ [qw(ab.txt ac.txt)], '' ], + [ [qw(ab ab/q.txt)], '' ], + [ [qw(/ab /ab/q.txt)], '' ], + [ [qw(ab/ ab/q.txt)], 'ab' ], [ [qw(/a/b.txt /c/d.txt)], '' ], [ [qw(/a/q.txt)], '/a' ], [ [qw(/aa/q.txt /ab/q.txt)], '' ], @@ -26,6 +31,6 @@ sub common_path { ## Compute the common string.... $l = substr $l, 0, length( (($_^$l) =~ m{^(\0+)})[0]) for @_; ## Remove the trailing "/"s - substr $l, 0, rindex $l, '/'; + $l=~m{/} ? substr $l, 0, rindex $l, '/' : '' } |
