So I'm having a bit of a problem with a CGI script. It runs fine, except for the little problem that param(x) doesn't work at all. It will either crash the program or return an undefined value.

#!/usr/bin/perl
use warnings;
use CGI qw(:standard );

$temp=uc(param('class'));
$class=chomp ($temp);

$temp=uc(param('type'));
$type=chomp ($temp);

$temp=uc(param('first'));
$first=chomp ($temp);

$temp=uc(param('last'));
$last=chomp ($temp);

$temp=param('area');
$areacode=chomp($temp);

$temp=param('firstnum');
$first3=chomp($temp);

$temp=param('secondnum');
$last4=chomp($temp);

$temp=uc(param('carrier'));
$carrier=chomp($temp);

$num="$areacode$first3$last4";
open (PER, ">../data/USERS/$type/$first.$last.dat");
print (PER "$first $last\n$class\n$num\n$carrier");
close (PER);
print ("Content-Type:text/html\n\n");
print "<html><body>";
print '<h4>Thank you. Please email the Administrator at <a href="mailto:apcsci@gmail.com">xxxx@gmail.com</a> with any questions or comments</h4>';
print "</body></html>";

Thanks

start with a simple script. Use a form with one text field: 'test'.

#!/usr/bin/perl
use warnings;
use strict;
use CGI qw(:standard);
print header;
print start_html; 
print param('test');
print end_html;

if that still crashes then your install of perl is bad or is maybe a non standard distribution.

somehow theres a problem in the

$temp=uc(param('class'));
$class=chomp ($temp);

part, and not regarding the param('x'); call. the simple form worked fine, and i modified my script so that it doesn't convert to uppercase or chomp, and now it's working

EDIT: Well now I feel really stupid. $first=chomp($temp); would return the number of spaces removed, not the string after the spaces had been removed. Oops haha

ahh...my bad, I also missed that. You should not assign a return value from the chomp function, it should just be:

$var = "some value\n";
chomp($var);

Note: chomp() only removes the input record seperator from the end of a line or string, which is generally a newline, it does not remove spaces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.