FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 09-01-2018, 03:20 PM   Postid: 186667
ricktrip
Site Owner
 
ricktrip's Avatar

Forum Notability:
26 pts: User-friendly
[Post Feedback]
 
Join Date: Oct 2003
Posts: 81
trouble with newlines

I've been having trouble with something that seems simple, but has kept me stumped for a couple of days. Heads up: I'm not a professional programmer. I'm very familiar with the book Learning Perl but largely foggy with Intermediate Perl.

My frustration is with getting newlines to work. The following code isolates my problem:
Code:
#!/usr/bin/perl

# trial.cgi

my $query = "student_id=triplett-1&submitButtonName=REGISTER";
my @name_value_pairs = split /&/, $query;

print "Content-type: text/html\n\n";
print "$name_value_pairs[0]\n";
print "$name_value_pairs[1]\n";
print;

foreach my $pair (@name_value_pairs){
    print "$pair\n";
}

print $name_value_pairs[0];
print;
print;
print $name_value_pairs[1];
die "$query";
exit;
The first PRINT ends with two newlines as it should, and the server balks without them. This is as expected. But the remaining newlines appear on my browser as spaces for some reason, instead of on separate lines. Below is a copy/paste from my browser screen:
Quote:
student_id=triplett-1 submitButtonName=REGISTER student_id=triplett-1 submitButtonName=REGISTER student_id=triplett-1submitButtonName=REGISTER
Also, I've tried replacing PRINT with SAY, but it won't compile. Maybe the version of the installed Perl?

Any comments/guesses will be most welcome!

Rick
ricktrip is offline   Reply With Quote
Old 09-01-2018, 04:06 PM   Postid: 186668
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: trouble with newlines

HTML is a markup language. If you use text/html as you content type then the browser will want HTML syntax. If you want plain newlines to work use text/plain as your content type.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 09-01-2018, 04:18 PM   Postid: 186669
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: trouble with newlines

Also, I am not sure if you knew it or not but putting the die command at the end will cause that output to end up in the error log file instead of the browser.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 09-01-2018, 04:27 PM   Postid: 186670
ricktrip
Site Owner
 
ricktrip's Avatar

Forum Notability:
26 pts: User-friendly
[Post Feedback]
 
Join Date: Oct 2003
Posts: 81
Re: trouble with newlines

Ah! (smacks his head). I knew I was overlooking something simple. Many thanks, Kevin! I'm going to have a drink in your honor!
ricktrip is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:25 AM.


Running on vBulletin®
Copyright © 2000 - 2019, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2019 FutureQuest, Inc.
FutureQuest, Inc.