The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Sorting using multpile criterias
Discuss Sorting using multpile criterias in the Perl Programming forum on Dev Shed. Sorting using multpile criterias Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 1st, 2000, 08:47 AM
|
|
Junior Member
|
|
Join Date: Mar 2000
Posts: 7
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
|

May 2nd, 2000, 03:16 AM
|
|
Guest
|
|
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.
|

May 2nd, 2000, 07:35 AM
|
|
Junior Member
|
|
Join Date: Mar 2000
Posts: 7
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?
|

May 2nd, 2000, 08:37 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|