From a316c58217d8984c9ba64c5bbde8f52efe73680c Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 20 Jun 2012 14:50:39 +0100 Subject: [PATCH] Tweaking handling of initial slash detection to handle initial undefs. --- Utils.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Utils.pm b/Utils.pm index b457c35..17841b9 100644 --- a/Utils.pm +++ b/Utils.pm @@ -49,9 +49,7 @@ our @EXPORT_OK = qw(path_join resolve_path check_directory load_file save_file s # @return A string containing the path fragments joined with forward slashes. sub path_join { my @fragments = @_; - - # Need a lead slash? - my $leadslash = $fragments[0] =~ m|^/|; + my $leadslash; # strip leading and trailing slashes from fragments my @parts; @@ -59,6 +57,9 @@ sub path_join { # Skip empty fragments. next unless($bit); + # Determine whether the first real path has a leading slash. + $leadslash = $bit =~ m|^/| unless(defined($leadslash)); + # Remove leading and trailing slashes $bit =~ s|^/*||; $bit =~ s|/*$||;