Hi Rick, On Sun, 2 Sep 2018 16:04:26 -0500 Rick T <p...@reason.net> wrote:
> I am trying to wean myself from CGI.pm, an easy task for most of you, but I > am a beginner. The code below works, but that does not mean it always will or > that it cannot be improved. I found the main part of this in CGI Programming > with Perl, which is 18 years old, and I’ve given up hoping that a new edition > of it will come out. I’ve read somewhere that servers can give the wrong > value for CONTENT_LENGTH, so I stuck in a second chance before bailing out; > and of course this may not be necessary or done well. I look forward to any > and all comments. I also would appreciate any guidance on how I can learn > more about CGI and how to deal with it. This book has been extremely valuable > to me, but even I can see that some of its guidance is a bit creaky! — Rick > > sub get_form_data { > my $query = q{}; # Empty string > my @name_value_pairs; > if ( read( STDIN, $query, $ENV{'CONTENT_LENGTH'} ) > == $ENV{CONTENT_LENGTH} > ){ > @name_value_pairs = split /&/, $query; > }elsif (! read( STDIN, $query, $ENV{'CONTENT_LENGTH'} ) # Second chance > == $ENV{CONTENT_LENGTH} > ){ > die "Trouble parsing POST request: $!" > } > please use a module - whether CGI.pm or other. See: * https://leejo.github.io/2016/02/22/all_software_is_legacy/ * https://plackperl.org/ * https://metacpan.org/release/CGI-Minimal Thanks to Uri too. Regards, Shlomi Fish > foreach my $pair (@name_value_pairs){ > my ($key, $value) = split /=/, $pair; > chomp ($key, $value); > $pf{$key} = $value; > } > return; > } > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ http://is.gd/i5eMQd - Emma Watson’s Interview for a Software Dev Job I love being convinced that I was wrong before. That way I knew I improved and am now wiser. Like the Klingon warriors say when it happens: “What a great day it was for me to die!”. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/