From: b Date: Wed, 5 Jul 2023 22:47:22 +0000 (+0000) Subject: write post data file X-Git-Tag: v1.0.14 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=refs%2Ftags%2Fv1.0.14;p=botm%2Fcommon-perl write post data file --- diff --git a/botm_common.pm b/botm_common.pm index 9ddb13d..cda92b6 100644 --- a/botm_common.pm +++ b/botm_common.pm @@ -25,11 +25,11 @@ use Encode ('encode', 'decode'); use Exporter; -our $VERSION = '1.0.13'; +our $VERSION = '1.0.14'; our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = ( - 'read_data_file', 'write_data_file', + 'read_data_file', 'write_data_file', 'write_postdata_file', 'read_header_file', 'url_encode', 'url_decode', 'url_query_encode', 'url_query_decode', @@ -316,6 +316,44 @@ sub write_data_file { return 1; } +# todo text +sub write_postdata_file { + (my $file, my $encoding_file, my $encoding_data, my $data) = @_; + my $fh; + + if ($encoding_file eq '') { + $encoding_file = 'UTF-8'; + } + + # check if $file is actually a path or maybe a filehandle + # filehandles are references. + if(ref($file)) { + $fh=$file; + unless (seek($fh, 0, 0)) { + # return 0; + } + } + else { + unless (open ($fh, ">:encoding($encoding_file)", encode('locale_fs', $file))) { + return 0; + } + } + + my $data_encoded = url_query_encode($data, $encoding_data); + + print $fh $data_encoded."\n"; + + # If argument was a path the file must be closed. + unless (ref($file)) { + close ($fh); + } + else { + # cut off any remaining old file content, + truncate ($fh , tell($fh)); + } + + return 1; +} ###################