From 29f4a0d68bcb31fb4032b61f191b0b88a1be922f Mon Sep 17 00:00:00 2001 From: b Date: Fri, 12 May 2023 22:07:34 +0000 Subject: [PATCH] join_path() --- botm_common.pm | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/botm_common.pm b/botm_common.pm index f882aad..a2f7abd 100644 --- a/botm_common.pm +++ b/botm_common.pm @@ -25,10 +25,10 @@ use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # vX.Y.Z: X YYYZZZ -$VERSION = 1.000001; +$VERSION = 1.000002; @ISA = qw(Exporter); @EXPORT = (); -@EXPORT_OK = qw(readdatafile writedatafile); +@EXPORT_OK = qw(readdatafile writedatafile join_path); %EXPORT_TAGS = (); ################## @@ -226,4 +226,29 @@ sub writedatafile { } + +# join_path() builds a path (or url) from individual segments +# that there will be 1 path separator brtween (and not 2 or 0). +sub join_path { + (my $joiner, my @segments) = @_; + + my $path = ''; + foreach my $segment (@segments) { + if ($path eq '') { + $path = $segment; + } + else { + unless (substr ($path, -1) eq $joiner) { + $path .= $joiner; + } + if (substr ($segment, 0, 1) eq $joiner) { + $path = $segment; + } + else { + $path .= $segment; + } + } + } + return $path; +} 1 -- 2.30.2