in reply to Re: appending to html at beginning (use CGI)
in thread appending to html at beginning

Hi Anonymous,

That's how I would have done it too, years ago* - now, CGI's own documentation says:

CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with CGI::Alternatives.

* Update: Okay, I admit I have sinned more recently than that. But only because (I thought) I knew what I was doing :-) And I still wouldn't recommend CGI to newcomers, who are more likely to misuse the module.

Regards,
-- Hauke D

  • Comment on Re^2: appending to html at beginning (don't use CGI)

Replies are listed 'Best First'.
Re^3: appending to html at beginning ( use CGI for parsing cgi)
by Anonymous Monk on Feb 03, 2017 at 13:03 UTC
    Did you look at the op? Op wrote and ran a cgi program. But is hand parsing...reinventing the cgi.pm module-- cgi module is best for doing that; every time you quote that when if doesnt apply is trolling
      Hey :-)
      Wow Ok, Got a lot to learn.. Didnt know that Matts guestbook script was such risky business... (altho my webserver is very dear to me - its just a personal playground, and I take a backup often, besides - I think the hiawatha webserver should be pretty secure) - But wow - many interesting suggestions - "swapping" file content with a temp text file seems actually quite understandable - but then - wow - the idea with a separate text file just listing all the stories is also a gem - because then one could - have links to a html file with all the different $names of peoples stories - so instead of just all stories being listed - one could click on someones name and their story would come up, that would be very cool.
      Anonymous Monk: yeah, probably better to just start from scratch listing all the $variables - eh stupid question, why do you all put "my" in front of the scalars?
        stupid question, why do you all put "my" in front of the scalars?

        Not stupid at all - it is to limit the scope. This is a very important concept in computing generally and is not just limited to Perl. However, you could do an awful lot worse than read the canonical article by Dominus: Coping with Scoping which deals with the whole issue of variable declaration in Perl. It goes into more depth that you'll need just now but it won't steer you wrong.

      Hi Anonymous,

      cgi module is best for doing that

      Plack, Catalyst, Dancer2, Mojolicious, and more... (Update: As hippo pointed out, CGI::Minimal, CGI::Lite, or CGI::Simple)

      - versus -

      A module that is no longer recommended by its own documentation, and was removed from Perl's core. I didn't even say the module was summarily bad, just that it shouldn't be recommended for newcomers/new developments.

      You're using some strange definitions of "best" and "trolling" ;-P

      Regards,
      -- Hauke D

        Please - Plack and all the frameworks building on it are a far conceptual step away from CGI programs. If you want people to switch away from hand-parsing CGI parameters, I think it's better to lead them the longer but easier way via CGI.pm than leading them to the cliff that are HTTP frameworks.

        #!/usr/bin/env plackup use strict; use warnings; use Data::Dumper; use Plack::Request; use Plack::Response; my $app = sub { my $req = Plack::Request->new( shift ); my $q = $req->parameters; my $navn = $q->{navn}; my $navn2 = $q->{navn2}; my $adj1 = $q->{adj1}; my $bann1 = $q->{bann1}; my $res = Plack::Response->new( 200 ); $res->body( $readystory ); $res->finalize; };
        VERSUS
        use CGI (); my $q = CGI->new; my $navn = $q->param('navn'); my $navn2 = $q->param('navn2'); my $adj1 = $q->param('adj1'); my $bann1 = $q->param('bann1'); ... print $q->header, $readystory;
        Furthermore:
        vagrant@localhost ~ $ cpanm --notest Plack --> Working on Plack Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Plack-1.0043.tar +.gz ... OK ==> Found dependencies: File::ShareDir::Install --> Working on File::ShareDir::Install Fetching http://www.cpan.org/authors/id/E/ET/ETHER/File-ShareDir-Insta +ll-0.11.tar.gz ... OK ==> Found dependencies: Module::Build::Tiny --> Working on Module::Build::Tiny Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Module-Build-Tiny-0 +.039.tar.gz ... OK ==> Found dependencies: ExtUtils::Config, ExtUtils::Helpers, ExtUtils: +:InstallPaths --> Working on ExtUtils::Config Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-Config-0.0 +08.tar.gz ... OK Configuring ExtUtils-Config-0.008 ... OK Building ExtUtils-Config-0.008 ... OK Successfully installed ExtUtils-Config-0.008 --> Working on ExtUtils::Helpers Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-Helpers-0. +026.tar.gz ... OK Configuring ExtUtils-Helpers-0.026 ... OK Building ExtUtils-Helpers-0.026 ... OK Successfully installed ExtUtils-Helpers-0.026 --> Working on ExtUtils::InstallPaths Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-InstallPat +hs-0.011.tar.gz ... OK Configuring ExtUtils-InstallPaths-0.011 ... OK Building ExtUtils-InstallPaths-0.011 ... OK Successfully installed ExtUtils-InstallPaths-0.011 Configuring Module-Build-Tiny-0.039 ... OK Building Module-Build-Tiny-0.039 ... OK Successfully installed Module-Build-Tiny-0.039 Configuring File-ShareDir-Install-0.11 ... OK Building File-ShareDir-Install-0.11 ... OK Successfully installed File-ShareDir-Install-0.11 Configuring Plack-1.0043 ... OK ==> Found dependencies: File::ShareDir, Cookie::Baker, Test::TCP, File +sys::Notify::Simple, HTTP::Entity::Parser, Stream::Buffered, Apache:: +LogFormat::Compiler, Devel::StackTrace::AsHTML, Hash::MultiValue, WWW +::Form::UrlEncoded, HTTP::Headers::Fast --> Working on File::ShareDir Fetching http://www.cpan.org/authors/id/R/RE/REHSACK/File-ShareDir-1.1 +02.tar.gz ... OK Configuring File-ShareDir-1.102 ... OK ==> Found dependencies: Class::Inspector --> Working on Class::Inspector Fetching http://www.cpan.org/authors/id/P/PL/PLICEASE/Class-Inspector- +1.31.tar.gz ... OK Configuring Class-Inspector-1.31 ... OK Building Class-Inspector-1.31 ... OK Successfully installed Class-Inspector-1.31 Building File-ShareDir-1.102 ... OK Successfully installed File-ShareDir-1.102 --> Working on Cookie::Baker Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/Cookie-Baker-0.0 +7.tar.gz ... OK Configuring Cookie-Baker-0.07 ... OK Building Cookie-Baker-0.07 ... OK Successfully installed Cookie-Baker-0.07 --> Working on Test::TCP Fetching http://www.cpan.org/authors/id/S/SY/SYOHEX/Test-TCP-2.17.tar. +gz ... OK Configuring Test-TCP-2.17 ... OK ==> Found dependencies: Test::SharedFork --> Working on Test::SharedFork Fetching http://www.cpan.org/authors/id/E/EX/EXODIST/Test-SharedFork-0 +.35.tar.gz ... OK Configuring Test-SharedFork-0.35 ... OK Building Test-SharedFork-0.35 ... OK Successfully installed Test-SharedFork-0.35 Building Test-TCP-2.17 ... OK Successfully installed Test-TCP-2.17 --> Working on Filesys::Notify::Simple Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Filesys-Notify-S +imple-0.12.tar.gz ... OK Configuring Filesys-Notify-Simple-0.12 ... OK Building Filesys-Notify-Simple-0.12 ... OK Successfully installed Filesys-Notify-Simple-0.12 --> Working on HTTP::Entity::Parser Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/HTTP-Entity-Pars +er-0.19.tar.gz ... OK Configuring HTTP-Entity-Parser-0.19 ... OK ==> Found dependencies: Hash::MultiValue, WWW::Form::UrlEncoded, HTTP: +:MultiPartParser, Stream::Buffered, JSON::MaybeXS --> Working on Hash::MultiValue Fetching http://www.cpan.org/authors/id/A/AR/ARISTOTLE/Hash-MultiValue +-0.16.tar.gz ... OK Configuring Hash-MultiValue-0.16 ... OK Building Hash-MultiValue-0.16 ... OK Successfully installed Hash-MultiValue-0.16 --> Working on WWW::Form::UrlEncoded Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/WWW-Form-UrlEnco +ded-0.24.tar.gz ... OK Configuring WWW-Form-UrlEncoded-0.24 ... OK Building WWW-Form-UrlEncoded-0.24 ... OK Successfully installed WWW-Form-UrlEncoded-0.24 --> Working on HTTP::MultiPartParser Fetching http://www.cpan.org/authors/id/C/CH/CHANSEN/HTTP-MultiPartPar +ser-0.01.tar.gz ... OK Configuring HTTP-MultiPartParser-0.01 ... OK Building HTTP-MultiPartParser-0.01 ... OK Successfully installed HTTP-MultiPartParser-0.01 --> Working on Stream::Buffered Fetching http://www.cpan.org/authors/id/D/DO/DOY/Stream-Buffered-0.03. +tar.gz ... OK Configuring Stream-Buffered-0.03 ... OK Building Stream-Buffered-0.03 ... OK Successfully installed Stream-Buffered-0.03 --> Working on JSON::MaybeXS Fetching http://www.cpan.org/authors/id/E/ET/ETHER/JSON-MaybeXS-1.0030 +09.tar.gz ... OK Configuring JSON-MaybeXS-1.003009 ... OK ==> Found dependencies: Cpanel::JSON::XS --> Working on Cpanel::JSON::XS Fetching http://www.cpan.org/authors/id/R/RU/RURBAN/Cpanel-JSON-XS-3.0 +227.tar.gz ... OK Configuring Cpanel-JSON-XS-3.0227 ... OK Building Cpanel-JSON-XS-3.0227 ... OK Successfully installed Cpanel-JSON-XS-3.0227 Building JSON-MaybeXS-1.003009 ... OK Successfully installed JSON-MaybeXS-1.003009 Building HTTP-Entity-Parser-0.19 ... OK Successfully installed HTTP-Entity-Parser-0.19 --> Working on Apache::LogFormat::Compiler Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/Apache-LogFormat +-Compiler-0.33.tar.gz ... OK Configuring Apache-LogFormat-Compiler-0.33 ... OK ==> Found dependencies: POSIX::strftime::Compiler --> Working on POSIX::strftime::Compiler Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/POSIX-strftime-C +ompiler-0.42.tar.gz ... OK Configuring POSIX-strftime-Compiler-0.42 ... OK Building POSIX-strftime-Compiler-0.42 ... OK Successfully installed POSIX-strftime-Compiler-0.42 Building Apache-LogFormat-Compiler-0.33 ... OK Successfully installed Apache-LogFormat-Compiler-0.33 --> Working on Devel::StackTrace::AsHTML Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Devel-StackTrace +-AsHTML-0.15.tar.gz ... OK Configuring Devel-StackTrace-AsHTML-0.15 ... OK Building Devel-StackTrace-AsHTML-0.15 ... OK Successfully installed Devel-StackTrace-AsHTML-0.15 --> Working on HTTP::Headers::Fast Fetching http://www.cpan.org/authors/id/T/TO/TOKUHIROM/HTTP-Headers-Fa +st-0.21.tar.gz ... OK Configuring HTTP-Headers-Fast-0.21 ... OK Building HTTP-Headers-Fast-0.21 ... OK Successfully installed HTTP-Headers-Fast-0.21 Building Plack-1.0043 ... OK Successfully installed Plack-1.0043 23 distributions installed

        Plack, Catalyst, Dancer2, Mojolicious, and more...

        All of those run slower then CGI.pm under CGI -- thats because they do a lot more than parse CGI parameters, have more dependencies, have bigger APIs ...

        (Update: As hippo pointed out, CGI::Minimal, CGI::Lite, or CGI::Simple) A module that is no longer recommended by its own documentation, and was removed from Perl's core. I didn't even say the module was summarily bad, just that it shouldn't be recommended for newcomers/new developments.

        By that logic, why would you even mention those other CGI::... modules?

        They were never in the perl core

        and they're just lesser imitations of the CGI.pm module

        You're using some strange definitions of "best" and "trolling" ;-P

        Look, its nice you've got enthusiasm for participation,

        but you should avoid railing against things, esp by copy/paste,

        thats just trolling

        Code over propaganda