[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
[mv] Getting @keys from %DB in Perl structures
****** message to minivend-users from Randy Moore <ramoore@axion-it.net> ******
Hi All,
I'm trying to learn to properly use the %Db structure inside of a [perl] tag.
I'm close, but I'm missing one (probably trivial) thing: How to get an
array of keys for a database.
Specifically, I'm trying to loop through every item in my products
database. If I pass the list of keys into my Perl through a scratch
variable, my code works fine, but this seems grossly inefficient.
The docs at
http://www.minivend.com/minivend/docindex/10.00.MiniVend_Perl_Objects.html
show examples using an '@keys' array, but never show how to create that array.
Here is the bit of code I'm playing with (it prepares an alphabetical index
to my product titles, suppressing letters where no product title starts
with that letter)
[seti name=codelist][tag each products][loop-code],[/tag][/seti]
[perl products]
my($title, $retval, $code, $ref, %seen, $first);
my(@codelist) = split(/,/, $Scratch->{codelist});
$ref = $Db{products};
foreach (@codelist) {
$code = $_;
$title = $ref->field($code, "title");
$first = uc(substr($title,0,1));
$seen{$first}++;
}
foreach $Alpha ('A' .. 'Z') {
if ($seen{$Alpha}) {
$retval .= "[page href=\"alpha\" arg=\"$Alpha\"]
$Alpha</A> \n";
}
}
return "$retval";
[/perl]
It would seem much more reasonable to get my '@codelist' array directly
from my $ref to $Db{products}.
I've tried several variations with
$ref->field_accessor($ref->config('KEY')) and
$ref->column_index($ref->config('KEY')) but could not make it work.
Any suggestions?
Randy Moore
Axion Information Technologies, Inc.
email ramoore@axion-it.net
phone 301-408-1200
fax 301-445-3947
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list