From c4843959c15d793dca50517c28dee25ddecbe275 Mon Sep 17 00:00:00 2001 From: b Date: Tue, 13 Jun 2023 23:05:37 +0000 Subject: [PATCH] make temp file name --- botm_common.pm | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/botm_common.pm b/botm_common.pm index f2d48ca..aa17f8f 100644 --- a/botm_common.pm +++ b/botm_common.pm @@ -18,6 +18,7 @@ package botm_common; use strict; #use warnings; use utf8; +use feature 'state'; use Encode qw(encode decode); @@ -25,7 +26,7 @@ use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # vX.Y.Z: X YYYZZZ -$VERSION = 1.000009; +$VERSION = 1.000010; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = ( @@ -34,7 +35,7 @@ $VERSION = 1.000009; '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', + 'join_path', 'make_temp_path' ); %EXPORT_TAGS = (); @@ -67,6 +68,31 @@ sub join_path { return $path; } +sub make_temp_path { + (my $dir, my $basename) = @_; + + my $filename; + my $ext; + my $ind = rindex($basename, '.'); + state $id = 0; + + if ($ind >= 0) { + $filename = substr($basename, 0, $ind); + $ext = substr($basename, $ind); + } + else { + $filename = $basename; + $ext = ''; + } + if ($filename ne '') { + $filename .= '.'; + } + $filename .= $$ . '.' . $id . '.' . time() . $ext; + $id++; + + return join_path('/', $dir, $filename); +} + ################## -- 2.30.2