I'm new with L2, and have only been working on it a day or two. I do not write Perl, but I can read it a bit and figure out some of the logic. I've worked this up to where I need help, I might have part of the answer below, but need to know exactly how to code build_sorthit and %db_def .
I've added and rearranged some fields in links.db and gotten it all to multi-level sort based on "Yes,No" for fields 15,16, & 17 (isBest, Priority, SortRank). But I want to be able to finesse link return order a little more closely. To do this "Yes,No" would be replaced by drop-downs.
isBest = A1,A2,A3,A4,A5,A6,A7,A8,A9,B0,C0,ZZ
Priority = B1,B2,B3,B4,B5,B6,B7,B8,B9,C0,ZZ
SortRank = C1,C2,C3,C4,C5,C6,C7,C8,C9,ZZ
for each of these three fields. Thus, A1B1C1 would be the highest return, and ZZZZZZ would be the default where the link title alpha would kick in and order them from there on out. The other typical sorts like isNew
and hits would be nice if I can keep them, but not mandatory.
Unless it's easy to call multilevel numeric sorts in Perl, leaving the above 3 fields as alpha will work if you can concatenate them into a single sort parameter, which I believe I saw on the Links forum elsewhere:
==============
(trying a multi-field sort, last name, first name, middle name)
see
http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001857.html
Don't worry anymore about creating a new field to store the rsults of appending Field1
+ Field2 + Field3 or adding something to:
# Field number to sort links by:
$db_sort_links = 1;
It uses a temp Mem Var and does everything on the fly ... right ?
Oh and the code should actually be:
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_field1+ $offset, $db_field2 + $offset, $field3 + $offset]);
_________now back to this posting_________________________
??? So, my sort set-up would look like this (see links.def, below) ????
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_isbest+ $offset, $db_priority + $offset, $db_sortrank + $offset]);
???? But what's the rest??
Below is what I have working on the current "Yes,No" sort return ordering.
____________CURRENT_FILES_BELOW_HERE_______________
File: links.def
# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
HidKey => [14, 'alpha', 40, 500, 1, '', ''],
isBest => [15, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Priority => [16, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
SortRank => [17, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Graphic => [18, 'alpha', 40, 75, 0, '', ''],
Gwidth => [19, 'alpha', 5, 5, 0, '', ''],
Gheight => [20, 'alpha', 5, 5, 0, '', '']
);
________________________________________________________________
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_title = 1; $db_url = 2; $db_modified = 3;
$db_category = 4; $db_contact_name = 6;
$db_contact_email = 7; $db_hits = 8; $db_isnew = 9;
$db_ispop = 10; $db_rating = 11; $db_votes = 12;
$db_mail = 13; $db_hidkey = 14; $db_isbest=15;
$db_priority = 16; $db_sortrank=17;
________________________________________________________________
# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Rating => '0',
Votes => '0',
ReceiveMail => 'Yes',
HidKey => 'No',
isBest => 'No',
Priority => 'No',
SortRank => 'No'
);
________________________________________________________________
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No',
isBest => 'Yes,No',
Priority => 'Yes,No',
SortRank => 'Yes,No'
);
========================================================
========================================================
File: db_utils.pl
sub build_sorthit {
# --------------------------------------------------------
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isbest, %priority, %sortrank, %isnew, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isbest + ($i * ($#db_cols+1))] eq "Yes") and ($isbest{$i} = 1);
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_sortrank + ($i * ($#db_cols+1))] eq "Yes") and ($sortrank{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
}
foreach $hit (sort {
($isbest{$b} and !$isbest{$a}) and return 1;
($isbest{$a} and !$isbest{$b}) and return -1;
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($sortrank{$b} and !$sortrank{$a}) and return 1;
($sortrank{$a} and !$sortrank{$b}) and return -1;
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($isbest{$a} and $isbest{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($sortrank{$a} and $sortrank{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
Thanks for any help on this.
Bob Jordan
ICW.NET
[This message has been edited by bjordan (edited June 17, 1999).]
I've added and rearranged some fields in links.db and gotten it all to multi-level sort based on "Yes,No" for fields 15,16, & 17 (isBest, Priority, SortRank). But I want to be able to finesse link return order a little more closely. To do this "Yes,No" would be replaced by drop-downs.
isBest = A1,A2,A3,A4,A5,A6,A7,A8,A9,B0,C0,ZZ
Priority = B1,B2,B3,B4,B5,B6,B7,B8,B9,C0,ZZ
SortRank = C1,C2,C3,C4,C5,C6,C7,C8,C9,ZZ
for each of these three fields. Thus, A1B1C1 would be the highest return, and ZZZZZZ would be the default where the link title alpha would kick in and order them from there on out. The other typical sorts like isNew
and hits would be nice if I can keep them, but not mandatory.
Unless it's easy to call multilevel numeric sorts in Perl, leaving the above 3 fields as alpha will work if you can concatenate them into a single sort parameter, which I believe I saw on the Links forum elsewhere:
==============
(trying a multi-field sort, last name, first name, middle name)
see
http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001857.html
Don't worry anymore about creating a new field to store the rsults of appending Field1
+ Field2 + Field3 or adding something to:
# Field number to sort links by:
$db_sort_links = 1;
It uses a temp Mem Var and does everything on the fly ... right ?
Oh and the code should actually be:
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_field1+ $offset, $db_field2 + $offset, $field3 + $offset]);
_________now back to this posting_________________________
??? So, my sort set-up would look like this (see links.def, below) ????
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_isbest+ $offset, $db_priority + $offset, $db_sortrank + $offset]);
???? But what's the rest??
Below is what I have working on the current "Yes,No" sort return ordering.
____________CURRENT_FILES_BELOW_HERE_______________
File: links.def
# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
HidKey => [14, 'alpha', 40, 500, 1, '', ''],
isBest => [15, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Priority => [16, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
SortRank => [17, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Graphic => [18, 'alpha', 40, 75, 0, '', ''],
Gwidth => [19, 'alpha', 5, 5, 0, '', ''],
Gheight => [20, 'alpha', 5, 5, 0, '', '']
);
________________________________________________________________
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_title = 1; $db_url = 2; $db_modified = 3;
$db_category = 4; $db_contact_name = 6;
$db_contact_email = 7; $db_hits = 8; $db_isnew = 9;
$db_ispop = 10; $db_rating = 11; $db_votes = 12;
$db_mail = 13; $db_hidkey = 14; $db_isbest=15;
$db_priority = 16; $db_sortrank=17;
________________________________________________________________
# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Rating => '0',
Votes => '0',
ReceiveMail => 'Yes',
HidKey => 'No',
isBest => 'No',
Priority => 'No',
SortRank => 'No'
);
________________________________________________________________
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No',
isBest => 'Yes,No',
Priority => 'Yes,No',
SortRank => 'Yes,No'
);
========================================================
========================================================
File: db_utils.pl
sub build_sorthit {
# --------------------------------------------------------
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isbest, %priority, %sortrank, %isnew, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isbest + ($i * ($#db_cols+1))] eq "Yes") and ($isbest{$i} = 1);
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_sortrank + ($i * ($#db_cols+1))] eq "Yes") and ($sortrank{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
}
foreach $hit (sort {
($isbest{$b} and !$isbest{$a}) and return 1;
($isbest{$a} and !$isbest{$b}) and return -1;
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($sortrank{$b} and !$sortrank{$a}) and return 1;
($sortrank{$a} and !$sortrank{$b}) and return -1;
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($isbest{$a} and $isbest{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($sortrank{$a} and $sortrank{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
Thanks for any help on this.
Bob Jordan
ICW.NET
[This message has been edited by bjordan (edited June 17, 1999).]