ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have no clue about programming, however I manage (by error and trial mainly) to modify preexisting scripts. But this thing is killing me! I have the following code in a perl script that should write html form input to a file and return the same parameter/value pairs back to the internet page so the person can read what he/she submitted.
The data that's written to the file is nicely formatted, i.e. with line breaks. However, and here is my problem:
The parameter/value pairs that are returned to the page are all in one line. Whatever I try, with /n or <br>, it has no effect.
Here is part of the perl script. The bold part is the problem.
Code:
print FILEHANDLE "--Submitted--: $Hour:$Minute $Day-$Month-$Year\n"; #write to file
print "<h2>Thank you for your registration!</h2><br>";
print "<h3>The following details have successfully been submitted at $Hour:$Minute $Day-$Month-$Year:</h3><br>"; #writes to page
print "";
foreach $parameter (@params) {
print FILEHANDLE "$parameter:" . param($parameter) ,"\n"; #writes to file
print "$parameter " . param($parameter) ,"<br>"; #writes to page
}
print FILEHANDLE "\n";
close (FILEHANDLE); #close the file
print end_html;
This is what I now get returned to the page:
Code:
title Dr. firstname=Leon lastname=blabla institute=blabla department=blabla address1= address2= city= zip= country= tel= email= info=More blabla
Originally posted by LJSBrokken
[B] print "$parameter " . param($parameter) ,"<br>"; #writes to page
Try:
Code:
print "$parameter " . param($parameter) ."<br>"; #writes to page
i.e. replace the comma with a dot. With a comma, the <br> is passed as a second parameter to print. I'm not quite sure how Perl handles this, but you can find out with:
Code:
perldoc -f print
With a dot between two strings, Perl will concatenate the two strings and treat them as a single parameter to print.
First off, with XHTML you should use <br/> not <br> (in XHTML, all tags must be closed; using a / at the end of the tag is a short-hand for spelling out the closing tag).
You also have no <p>…</p> tag enclosing the text in the body. You can't just type text, it needs to be enclosed in a block-level tag such as <p> or <hnumber>. You might like to look at http://validator.w3.org/
You do seem to be missing the <br> from the end of each line. I'm not certain what's happening to cause this problem; do you get this with a dot as well as with a comma? I would suggest trying it as two commands:
Code:
print "$parameter " . param($parameter); # writes to page
print "<br>\n"; #writes to page
Genjix:
I know the line breaks are missing, my question was how to modify the perl script so they would be there.
Rjlee:
Why does the code get returned as XHTML and not HTML?
Writing it as two separate lines gives exactly the same result (source code also). Similar when I write <br/> instead of <br>. As judged from the html source, it appears that the <br> only gets added after the whole list of parameters (or am I wrong?), instead of after each of them.
Where would I add the <p>....</p> in the perl script?
Here's the complete perl script I use, maybe that will shed a light on the matter:
Code:
#!/usr/bin/perl
use CGI qw(:standard);
print header;
print start_html('Registration');
if (param()) {
@params=param();
($Second,$Minute,$Hour,$Day,$Month,$Year,$WeekDay,$DayOfYear,$IsDST)=localtime(time());
unless(open (FILEHANDLE, '>>/www/users/l/leobro/participants.txt')) #open file for appending
{
print "could not open file";
print end_html;
exit(0);
}
$Month+=1;
$Year+=1900;
print FILEHANDLE "--Submitted--: $Hour:$Minute $Day-$Month-$Year\n"; #write to file
print "<h2>Thank you for your registration!</h2>";
print "<h3>The following details have successfully been submitted at $Hour:$Minute $Day-$Month-$Year:</h3>"; #writes to page
print "";
foreach $parameter (@params) {
print FILEHANDLE "$parameter:" . param($parameter) ,"\n"; #writes to file
print "$parameter " . param($parameter);
print "<br>\n"; #writes to page
}
print FILEHANDLE "\n";
close (FILEHANDLE); #close the file
print end_html;
}else{
print "You need to have a html form to pass parameters from";
print end_html;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.