Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Problem with Perl script for interactive web page


  • Please log in to reply

#1
lillya

lillya

    Member

  • Member
  • PipPip
  • 22 posts
:whistling: I am really new to both web page design and CGI programming. I am trying to make a site where I can gather simple data from people that visit my site (like their gender and ethnicity) but I keep getting an error with my CGI script. I have no idea what I am doing wrong and I can't seem to find the answer anywhere. My script is as follows (written in Pearl)

#!/usr/bin/perl
use strict;
use CGI ':standard';

my ($gender, $age, $ethnicity, $relationship);

$gender= param('gender');
$age= param('age');
$ethnicity= param('ethnicity');
$relationship= param('relationship');

open (INFO, ">>$ENV{'DOCUMENT_ROOT'}/www/data/demographics.txt");
print INFO qq($gender, $age, $ethnicity, $relationship\n);
close (INFO);

print "Content-type: text/html\n\n";
print 'Thank you for participating in this research!';


The error I get refers to an uninitialized value in concatenation on line 13. The code I have above is everything so line 13 is the 13th line in that starts print INFO qq...

Any ideas of what I might be doing wrong? I checked two books I have on Perl and can't seem to figure it out.

Thanks!
  • 0

Advertisements


#2
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
Try putting no more than two concat statements on each line for the longer ones. Especially line 13. Also, there is only one concatenation operator for PHP, and that is the period (.).

Example:

<?php
$address = ‘123 ‘ . str_replace(“|”,” “,$address)
. “<br />\n“ . $city
. “$state, $zipcode”;
?>

Hope I got this right. :whistling: Getting too old to try to remember all this out of my head anymore.

Ron
  • 0

#3
lillya

lillya

    Member

  • Topic Starter
  • Member
  • PipPip
  • 22 posts
Thanks for the advice. The only problem is that I have no idea what you mean - specifically, I do not know any of the computer language so words like concatenation don't really make sense to me. Could you perhaps repeat your advice using regular lay language that I can understand without really knowing any programming specific words?

Thanks so much for your help.
  • 0

#4
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
Hi:

Let me give another example with comments and maybe it will help:

<?php

// set up some string variables
$a = 'Gender:';
$b = 'Age:';
$c = 'Birthday:';
$d = 'Sex:';

// combine them using the concatenation operator
// this returns 'Gender: Age: Birthday: Sex:<br />'
$statement = $a.' '.$b.' '.$c.' '.$d.'<br />';
print $statement;

// and this returns 'Birthday: Gender: Age: Sex:'
$command = $c.' '.$a.' '.$b.' '.$d.'!';
print $command;
?>

Notice print command set to one string variable. Could just as easily use: print "result is $result<br />"; if you change the $statement variable to $result.

To answer your actual question about concatenation see: Definitions at Answers.com

Let me know if we're getting anywhere on this. I would rewrite the print lines and simply them. Any one with more PHP is definitely welcome to jump in.

Ron
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP