cal has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am attempting to understand how I can read and print a single variable of form data from an SHTML web page into a small CGI script(Below)
Producing HTML that prints (what ever the value of 'Firstname' is)'is the value of $Firstname'. Thanks In the begining Let us first assume that there was nothing to begin with.
#!/usr/local/bin/perl -w use strict; use diagnostics; use CGI qw(:standard); print header(), start_html(-title=>"CGI.pm Example Script"), h1('Hello World!'), 'is the value of $Firstname', end_html(); exit (0);

Replies are listed 'Best First'.
Re: Reading form data and printing variables using CGI.pm
by gryphon (Abbot) on Jul 19, 2002 at 21:13 UTC

    Greetings cal,

    You're on the right track. You just need to define what $Firstname is going to be.

    my $Firstname = param('Firstname');

    Put that somewhere in front of your print statement and you're done.

    -gryphon
    code('Perl') || die;

      But how does the variable become associated to the HTML line? 'is the value of $Firstname', Thanks
      <code> #!/usr/local/bin/perl -w use strict; use diagnostics; use CGI qw(:standard); my $Firstname = param('Firstname'); print header(), start_html(-title=>"CGI.pm Example Script"), h1('Hello World!'), 'is the value of $Firstname', end_html(); exit (0);

        Greetings cal,

        In Perl, using a single quote simply reads a string literally, but a double quote interprets a string. In your code, you have single quotes around the string where you use $Firstname. So what gets printed is literally "$Firstname". You actually want Perl to interpret the variable, so...

        print header(), start_html( -title => 'CGI.pm Example Script'), h1('Hello World!'), "is the value of $Firstname", end_html();

        -gryphon
        code('Perl') || die;

        Huh?
        my $PERL_FAQ = "butterscoth"; print 'my $PERL_FAQ \n'; print "my $PERL_FAQ \n";

        ____________________________________________________
        ** The Third rule of perl club is a statement of fact: pod is sexy.