commit 243ee6026c41786b34043c25517ce8fb3bae9c33
parent cdafa972f61780ab296c62e6824ba0ee62d9690d
Author: Samir Parikh <noreply@samirparikh.com>
Date: Tue, 31 Jan 2023 14:27:25 +0000
work in progress commit
Diffstat:
M | spsp | | | 25 | ++++++++++++++++++++++--- |
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/spsp b/spsp
@@ -26,14 +26,16 @@
use warnings;
use strict;
+use lib "/home/compiler/perl5/lib/perl5";
use JSON;
use POSIX qw( strftime );
use Path::Tiny; # to prepend data to post_data file
+use Data::Dumper;
use feature qw( signatures );
no warnings qw( experimental::signatures );
### declare constants
-my $POST_DATA_FILENAME = "/home/compiler/programs/spsp/post_data";
+my $POST_DATA_FILENAME = "/home/compiler/programs/spsp/html/post_data";
my $ID_LENGTH = 4;
my $ID = "id";
my $TITLE = "title";
@@ -46,6 +48,8 @@ sub generate_post_id ( $id_length )
return join '', map $characters[ rand @characters ], 1 .. $id_length;
}
+### slurp the input into a scalar
+### https://www.perl.com/article/21/2013/4/21/Read-an-entire-file-into-a-string/
chomp( my $status = do { local $/; <> } );
### check to see if post_data file exists. If not, create it
@@ -67,9 +71,24 @@ my %post = (
);
my $json = JSON->new;
-my $json_post = $json->pretty->encode( \%post );
-print $json_post;
+my $json_post = $json->encode( \%post );
+print $json_post, "\n";
path( $POST_DATA_FILENAME )->spew_utf8( $json_post, $content );
+print "see if we can now read the file contents\n";
+open my $post_data_filehandle, '<', $POST_DATA_FILENAME
+ or die "Cannot open $POST_DATA_FILENAME: $!\n";
+
+my $data;
+my $json_decode = JSON->new;
+
+while ( <$post_data_filehandle> )
+{
+ chomp;
+ #print "$_\n";
+ $data = $json_decode->decode( $_ );
+ print $data;
+}
+
exit;