Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 8th, 2001, 02:53 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
Basic Perl Question

I'm making a perl message board, with a list file for the order of the topics. For some reason it adds a space on the end of each line of the list.cgi. How would I remove it?

Teckwiz

Reply With Quote
  #2  
Old October 8th, 2001, 03:27 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Start here -> http://forums.devshed.com/showthrea...21944&forumid=6

Replace \r\n with \s+

Reply With Quote
  #3  
Old October 8th, 2001, 04:23 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
still no.... let me give you some of the source code...

post.cgi
Quote:
open(FILE, ">$filetoopen") or die "Cannot open list.cgi";
print FILE "$nextid\r\n";
print FILE "@file";
close(FILE);


forums.cgi - part A[/b]
Quote:
$filetoopen = "$boardpath" . "forum$forum/list.cgi";
open(FILE, "$filetoopen") or die "Cannot open list.cgi";
@topics = <FILE>;
close(FILE);


[U]forums.cgi - part B

Quote:
foreach $topic(@topics){

if($topic eq ""){
}else{

$filetoopen = "$boardpath" . "forum$forum/@topics/1.thd";

open(FILE, "$filetoopen") or die "Cannot open $filetoopen: $!";
$topicstuff = <FILE>;
close(FILE);

($id, $topicname, $topicdescription, $topic, $startedby, $postmarker, $totalviews, $totalreplys, $lastposter) = split(/\|/, $topicstuff);

Reply With Quote
  #4  
Old October 8th, 2001, 06:19 PM
Benahimvp's Avatar
Benahimvp Benahimvp is offline
The Basketball Star
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2001
Location: H-Town
Posts: 550 Benahimvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to Benahimvp Send a message via Yahoo to Benahimvp
In post.cgi, just have this:
Code:
print FILE "$nextid\n";

instead of this:
Code:
print FILE "$nextid\r\n";

The \r is not needed and is probably causing the extra space...
__________________
-Ben Ilegbodu
(Around the Bend Web Designs)

Reply With Quote
  #5  
Old October 8th, 2001, 06:31 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
even when i didnt have that... it had it...
i even manually edit the file and still... i dunno

Reply With Quote
  #6  
Old October 8th, 2001, 06:39 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
nevermind

Reply With Quote
  #7  
Old October 8th, 2001, 06:46 PM
Benahimvp's Avatar
Benahimvp Benahimvp is offline
The Basketball Star
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2001
Location: H-Town
Posts: 550 Benahimvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to Benahimvp Send a message via Yahoo to Benahimvp
I think the following line may be a mistake:
Code:
$filetoopen = "$boardpath" . "forum$forum/@topics/1.thd";

Is it supposed to read:
Code:
$filetoopen = "$boardpath" . "forum$forum/$topic/1.thd";

?? That may be also why you're getting the extra spaces.

Reply With Quote
  #8  
Old October 9th, 2001, 05:07 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
I'll try that

Reply With Quote
  #9  
Old October 9th, 2001, 06:05 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> even when i didnt have that... it had it

If it's ^M, then that's \r\n. Note, ^M is not visible from cat list.cgi, use vi list.cgi instead.

If you have ^M, that was because you uploaded your scripts to your server via Windows in binary mode. To trim all that, just follow the link I posted earlier and do something like this:

perl -i -pne 's/\r\n/\n/g' *.pl or perl -i -pne 's/\r\n/\n/g' *.cgi

Yes, it takes wildcard so you don't have to do it one by one.

Reply With Quote
  #10  
Old October 9th, 2001, 06:57 PM
Teckwiz Teckwiz is offline
PERL Master
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 Teckwiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Teckwiz Send a message via AIM to Teckwiz Send a message via Yahoo to Teckwiz
i switched around the way i handle files so i dont need this anymore, thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Basic Perl Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT