From 70a54705d7c930699fc7678b3b03a6f934e74397 Mon Sep 17 00:00:00 2001 From: b Date: Thu, 17 Aug 2023 22:28:03 +0000 Subject: [PATCH] add dir_path() --- botm_common.pm | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/botm_common.pm b/botm_common.pm index 0f3f2d9..e83111d 100644 --- a/botm_common.pm +++ b/botm_common.pm @@ -35,7 +35,7 @@ our @EXPORT_OK = ( 'url_query_encode', 'url_query_decode', 'split_url', 'join_url', 'merge_url', 'html_entity_encode_dec', 'html_entity_encode_hex', 'html_entity_encode_name', 'html_entity_decode', - 'join_path', 'make_temp_path', + 'join_path', 'dir_path', 'make_temp_path', 'system_encoded', 'exec_encoded' ); @@ -68,6 +68,26 @@ sub join_path { return $path; } +sub dir_path { + (my $joiner, my $path) = @_; + my $ind = rindex($path, $joiner); + if ($ind < 0) { + return ('', $path); + } + elsif ($ind == 0) { + return ( + $joiner, + substr($path, $ind+length($joiner)) + ); + } + else { + return ( + substr($path, 0, $ind), + substr($path, $ind+length($joiner)) + ); + } +} + sub make_temp_path { (my $dir, my $basename) = @_; -- 2.30.2