]> bicyclesonthemoon.info Git - botm/common-perl/commitdiff
join_path() v1.0.2
authorb <rowerynaksiezycu@gmail.com>
Fri, 12 May 2023 22:07:34 +0000 (22:07 +0000)
committerb <rowerynaksiezycu@gmail.com>
Fri, 12 May 2023 22:07:34 +0000 (22:07 +0000)
botm_common.pm

index f882aad7d6b6dfdc146c659a10f836b5cd691279..a2f7abd48405382c6d142f51894baf3f734222c2 100644 (file)
@@ -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