|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Sorting using multpile criterias |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|