SunQuest
           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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 1st, 2000, 08:47 AM
jezebel jezebel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 7 jezebel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to make a bulletin board script, but I have some problems sorting the posts.
This is the piece of code that doen't work, or so it seems to me.
if($topic eq "dev"){
open(INFO, "$bbfile") | | print "Unable to open $bbfile! $!n";
}
if($topic eq "perl"){
open(INFO, "$perlfile");
}
else {
print "Error of some kind!";
}
@info = <INFO>;
close INFO;
foreach $line(@info) {
$count = $count+1;
}
close INFO;
if ($bel == ""){
$bel = "0";
}
if ($re == "1"){
$bel = "0";
}
push(@info, "$count; $re; $bel; $subj; $user; $now; $comment");
@line = split(';', $inputline);
for( $i=0; $line[$i]; $i++ ) {
$entry{$line[0]} .= $line[$i];
}
foreach $falt (sort( keys(%entry))){
print "$falt : $entry{$falt}n";
}
if($topic eq "dev"){
open(DATA, ">$bbfile") | | print "Unable to open $bbfile! $!n";
}
if($topic eq "perl"){
open(DATA, ">$perlfile")| | print "Unable to open $perlfile! $!n";
}
foreach $lines (@info){
chomp $lines;
print DATA "$linesn";
}
close DATA;
print $query->redirect("$selfurl?onclick=4&topic=$topic");
}

The posts in the textfiles are: unique ID, reply or new post, the ID this post belong to if any, name, subject, comment, time. The fields are separated by ; and this is really starting to bother me...
What I like the script to do is to sort the posts in numerical order, but if the third field is isn't 0 then the script should insert the post on the next line after the post with the same ID. Can someone help me? I've tried various url's and I've been reading perl in a nutshell, but I can't figure this one out.
tia Jezebel



Reply With Quote
  #2  
Old May 2nd, 2000, 03:16 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
if($topic eq "dev"){
open(INFO, "$bbfile") | | print "Unable to open $bbfile! $!n";
}
## change the following line to
## elsif ($topic eq "perl"){
if($topic eq "perl"){
open(INFO, "$perlfile") | | print "Unable to open $bbfile! $!n";
}
else {
## remove the following line if you had it somewhere not mentioned in your post
print "Content-type: text/htmlnn";
print "Error of some kind!";
## return false, quit it now without continuing
exit(0);
}
@info = <INFO>;
close INFO;
foreach $line(@info) {
$count = $count+1;
## is there a $count=0; somewhere? Are you trying to count how many lines in @info? if so, do this instead..
## @info = <INFO>;
## $count = @info;
## to increment it, add $count = $count+1; now
}
## remove the following line since INFO has been closed.
close INFO;
## this line has no reference at all. Plus, using ; as a delimiter is very bad idea. You now must explicitly disable ; character in all fields.
@line = split(';', $inputline);
##########################################
I am sure there are alot more errors of this script. I can't debug it with just the given section. This script doesn't seem to be a well written script to me at all. It could have been whole lot better if it's written in different way.

Reply With Quote
  #3  
Old May 2nd, 2000, 07:35 AM
jezebel jezebel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 7 jezebel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It seems like I still have alot to learn, doesn't it?
Perhaps it would be easier to get a hang of what the code's doing if I could show the whole thing, but it's about 180 lines of code. But I really would aprechiate any help I can get.
Please mail me at jezebel@netlords.net if someone has the time to spare?

Reply With Quote
  #4  
Old May 2nd, 2000, 08:37 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

As freebsd mentioned earlier,You should change the ";" deliminator to some other symbol(Pipe sign would be the right choice).

<<<

@line = split(';', $inputline);
for( $i=0; $line[$i]; $i++ ) {
$entry{$line[0]} .= $line[$i];
}
>>>

Where is the $inputline???.

i think the sort the posts in numerical order is not a big problem.

can you explain what is the following logic?
<<<

but if the third field is isn't 0 then the script should insert the post on the next line after the post with the same ID.

>>>


Show me the complete code then we will get an idea about your logic.



------------------
SR -
shiju.dreamcenter.net

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Sorting using multpile criterias


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 3 hosted by Hostway