
FishMonger
Veteran
/ Moderator
Feb 27, 2011, 9:26 AM
Post #3 of 12
(7416 views)
|
Re: [02walshe] Can't get PERL to process HTML form
[In reply to]
|
Can't Post
|
|
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.
#!/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)
|