The following script gave quite ugly results. Some perfectly legal
names got split up badly. I admit that the test was very specially
targeted to the things I could see *would* go wrong.
-------------------------- SPLITDIR-TEST.PL --------------------------
use File::Spec;
foreach my $d (
"FOO.BAR",
"[FOO.BAR]",
"FOO-.--BAR",
"FOO---.-.BAR",
"FOO.---.BAR",
"FOO---BAR",
"FOO.][000000.BAR]",
) {
print "splitdir(",$d,") ==> (", join(", ",File::Spec->splitdir($d)),")\n";
}
----------------------------------------------------------------------
$ perl splitdir-test.pl
splitdir(FOO.BAR) ==> (FOO, BAR)
splitdir([FOO.BAR]) ==> (FOO, BAR)
splitdir(FOO-.--BAR) ==> (FOO-, -, -BAR)
splitdir(FOO---.-.BAR) ==> (FOO-, --, -, BAR)
splitdir(FOO.---.BAR) ==> (FOO, -, --, BAR)
splitdir(FOO---BAR) ==> (FOO-, --BAR)
splitdir(FOO.][000000.BAR]) ==> (FOO, 000000, BAR])
----------------------------------------------------------------------
Yup, dashes that are parts of names (like "FOO---") get (incompletely,
for what was intended) split up, and ".---." didn't get entirely split
up. Also, in the last split, "000000" should not be there.
The attached patch fixes those problems, and possibly more. The
result is much more what I would expect:
----------------------------------------------------------------------
$ perl "-IUSER:[LEVITTE.WRK.PERL-HACKS]" splitdir-test.pl
splitdir(FOO.BAR) ==> (FOO, BAR)
splitdir([FOO.BAR]) ==> (FOO, BAR)
splitdir(FOO-.--BAR) ==> (FOO-, --BAR)
splitdir(FOO---.-.BAR) ==> (FOO---, -, BAR)
splitdir(FOO.---.BAR) ==> (FOO, -, -, -, BAR)
splitdir(FOO---BAR) ==> (FOO---BAR)
splitdir(FOO.][000000.BAR]) ==> (FOO, BAR])
----------------------------------------------------------------------
Cheers,
Richard
-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.
--
Richard Levitte | http://richard.levitte.org/ | Tunnlandsv. 52
Levitte Programming | http://www.lp.se/ | S-168 36 Bromma
T: +46-708-26 53 44 | | SWEDEN
"Price, performance, quality... choose the two you like"
--- File/Spec/VMS.pm 2004-07-23 02:41:53.000000000 +0200
+++ VMS.pm 2004-07-23 02:41:15.000000000 +0200
@@ -370,7 +370,19 @@
sub splitdir {
my($self,$dirspec) = @_;
- $dirspec =~ s/\]\[//g; $dirspec =~ s/\-\-/-.-/g;
+ $dirspec =~ tr/<>/[]/; # < and > ==> [ and ]
+ $dirspec =~ s/\]\[\./\.\]\[/g; # ][. ==> .][
+ $dirspec =~ s/\[000000\.\]\[/\[/g; # [000000.][ ==> [
+ $dirspec =~ s/\[000000\./\[/g; # [000000. ==> [
+ $dirspec =~ s/\.\]\[000000\]/\]/g; # .][000000] ==> ]
+ $dirspec =~ s/\.\]\[/\./g; # foo.][bar ==> foo.bar
+ while ($dirspec =~ s/(^|[\[\<\.])\-(\-+)($|[\]\>\.])/$1-.$2$3/g) {}
+ # That loop does the following
+ # with any amount of dashes:
+ # .--. ==> .-.-.
+ # [--. ==> [-.-.
+ # .--] ==> .-.-]
+ # [--] ==> [-.-]
$dirspec = "[$dirspec]" unless $dirspec =~ /[\[<]/; # make legal
my(@dirs) = split('\.', vmspath($dirspec));
$dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\Z(?!\n)//s;