CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [02walshe] Can't get PERL to process HTML form: Edit Log



FishMonger
Veteran / Moderator

Feb 27, 2011, 9:26 AM


Views: 3341
Re: [02walshe] Can't get PERL to process HTML form

param is a function/subroutine not a hash, so you need to use ( ) parens instead of { } braces.

Every Perl script you write should include the strict and warnings pragmas. They will help you by pointing out lots of coding mistakes like you have in this script.

It's better to use a lexical var for the filehandle instead of the bareword and you should be using the 3 arg form of open and you should ALWAYS check the return code of an open call to make sure it was successful and take action if it wasn't.

When closing a write/append filehandle, it's best practice to check its return code to make sure it was successful.

For readability, it's best practice to add a little horizontal whitespace on those assignments.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

open(my $booking_fh, '>>', "bookingform.csv")
or die "failed to open 'bookingform.csv' $!";

my $first_name = param('firstname');
my $last_name = param('lastname');
my $email_address = param('emailaddress');
my $email_address_confirmation = param('emailaddressconfirmation');

print $booking_fh "$last_name|$first_name|$email_address|$email_address_confirmation\n";
close $booking_fh or die "failed to close \$booking_fh $!";



(This post was edited by FishMonger on Feb 27, 2011, 9:29 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Feb 27, 2011, 9:29 AM
Post edited by FishMonger (Veteran) on Feb 27, 2011, 9:29 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives