From: b Date: Thu, 17 Aug 2023 22:28:03 +0000 (+0000) Subject: add dir_path() X-Git-Tag: v1.0.17~1 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=70a54705d7c930699fc7678b3b03a6f934e74397;p=botm%2Fcommon-perl add dir_path() --- 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) = @_;