From: b <rowerynaksiezycu@gmail.com>
Date: Fri, 12 May 2023 22:07:34 +0000 (+0000)
Subject: join_path()
X-Git-Tag: v1.0.2
X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=29f4a0d68bcb31fb4032b61f191b0b88a1be922f;p=botm%2Fcommon-perl

join_path()
---

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