in reply to perl CGI: updating hidden field values for self-referring url

tangent already solved it for you. Here's a recap with some style changes and security amendments.

use strict; use warnings; # Uninitialized errors are normal for this kind of CGI. no warnings "uninitialized"; # LWP was not being used. use CGI; # Do not leave this in the script production. use CGI::Carp qw(fatalsToBrowser); # ->new is better; search indirect object syntax problems. my $q = CGI->new; print $q->header, $q->start_html; my $previousTotal = $q->param('sumTotal'); # Printing raw user input is a serious security problem. # Adding 0 will numify and clobber strings like "<script />" print $q->h2("Previous Total:", $previousTotal + 0); my $currentTotal = $previousTotal + 2; # Don't need "print" for every op and please do not put "br"s # everywhere for formatting. print $q->h2("Current Total:", $currentTotal), $q->start_form( -name => 'addition', -method => 'GET' ), $q->hidden( -name => 'sumTotal', -override => 1, -value => $currentTotal ), $q->submit( -name => 'button', -value => 'Add 2' ), $q->end_form, $q->end_html; exit 0;

Replies are listed 'Best First'.
Re^2: perl CGI: updating hidden field values for self-referring url
by choroba (Cardinal) on Feb 17, 2014 at 19:54 UTC
    To solve "indirect object syntax problems", use
    my $q = 'CGI'->new; # my preferred
    or
    my $q = CGI::->new;

    The common CGI->new is still ambiguous.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I actually learned that from tobyink awhile back but have had trouble getting used to it as a style… it feels so pedantic, I look over my shoulder to see if anyone was watching whenever I type it. :P

      To solve "indirect object syntax problems", use

      Don't use single all-caps words as sub names, and you never run into the problem :)