on 01/11/2001 03:32 AM, Jochen Wiedmann at [EMAIL PROTECTED] wrote:
 
>> this sort section starting on line 236
>> 
>> @$rows = sort {
>> $i = 0;
>> do {
>> $colNum = $sortCols[$i++];
>> $desc = $sortCols[$i++];
>> $c = $a->[$colNum];
>> $d = $b->[$colNum];
>> if (!defined($c)) {
>> $result = -1;
>> } elsif (!defined($d)) {
>> $result = 1;
>> } elsif ($c =~ /^\s*[+-]?\s*\.?\s*\d/  &&
>> $d =~ /^\s*[+-]?\s*\.?\s*\d/) {
>> $result = ($c <=> $d);
>> } else {
>> $result = $c cmp $d;
>> }
>> if ($desc) {
>> $result = -$result;
>> }
>> } while ($result == 0  &&  $i < @sortCols);
>> $result;
>> } @$rows;
>> 
>> gives me an odd result when sorting this database using the DBD::CSV module
>> 
>> I'm doing some preliminary testing now that I've finally got all the little
>> brats to work together in MacPerl :), and I get this
>> 
>> # Argument "86nfgzmgh-hk-fg.ark" isn't numeric in ncmp, <GEN0> chunk 2849.
>> File 'Primus 8.5GB:Applications:MacPerl Ÿ:site_perl:SQL:Statement.pm'; Line
>> 247
>> # Argument "0wiztlmhrmgil-fghk.ark" isn't numeric in ncmp, <GEN0> chunk 2849.
>> File 'Primus 8.5GB:Applications:MacPerl Ÿ:site_perl:SQL:Statement.pm'; Line
>> 247
>> [big snip]
>> Count:14 Game: utother, File: ut-logo-map-space.zip, Title:
>> ut-logo-map-space,
>> Size: 13, Review: /nalicity/review.asp?Id=6498, Rating: 7
>> Count:15 Game: utother, File: ut-whitepalace][.zip, Title: ut-whitepalace][,
>> Size: 2486, Review: /nalicity/reviews/ut-whitepalace][.html, Rating: 8.5
>> Count:16 Game: utother, File: 13mutants-sp-ut.zip, Title: 13mutants-sp-ut,
>> Size: 3572, Review: /nalicity/reviews/13mutants-sp-ut.html, Rating: 7
>> Count:17 Game: utother, File: 9dragonsintro-utsp.zip, Title:
>> 9dragonsintro-utsp, Size: 2905, Review:
>> /nalicity/reviews/9dragonsintro-utsp.html, Rating: 3
>> 
>> when executing this statement:
>> 
>> #!perl -w
>> use strict;
>> use DBI;
>> 
>> my $connect_dir = "Primus 8.5GB:Applications:MacPerl Ÿ:Nalicity:ratings:DBI
>> testing:tables:";
>> 
>> my $dbh = DBI->connect("dbi:CSV:f_dir=${connect_dir};csv_sep_char=\,", '',
>> '', 
>> { RaiseError => 1 })
>> or die "Can't connect to database: $DBI::errstr";
>> 
>> # I even tried this, but no effect. :-(
>> $dbh->{csv_tables}->{'testmapslist'}->{'types'} =
>> [ Text::CSV_XS::IV(), Text::CSV_XS::PV(), Text::CSV_XS::PV(),
>> Text::CSV_XS::PV(), Text::CSV_XS::PV(), Text::CSV_XS::IV(),
>> Text::CSV_XS::PV(), Text::CSV_XS::NV(), ];
>> 
>> my $sth = $dbh->prepare(" SELECT * FROM testmapslist WHERE gametype =
>> 'utother' AND rating >= 0 ORDER BY coercename DESC ");
>> $sth->execute;
>> 
>> my($id, $gametype, $coercename, $filename, $title, $size, $review, $rating);
>> $sth->bind_columns(\($id, $gametype, $coercename, $filename, $title, $size,
>> $review, $rating));
>> 
>> my $count = 1;
>> while ($sth->fetchrow) {
>> print "Count:$count Game: $gametype, File: $filename, Title: $title, Size:
>> $size, Review: $review, Rating: $rating\n";
>> ++$count;
>> }
>> 
>> $dbh->disconnect;
>> 
>> exit 0;
>> 
>> I thought first of doing something like specifying the types using
>> 
>> SELECT id(num), gametype(char), coercename(char), etc.. WHERE .. blah blah
>> 
>> but that obviously didn't work, despite the seeming simplicity and
>> obviousness 
>> of doing it that way, although it is also quite messy.
>> 
>> Is there any way around this? If you've patched this in later versions of
>> SQL::Statement, is there a way I can fix it for this version until someone
>> ports a more recent one?
>> 
>> Basically, I've created the 'coercenames' to force the 'numerically-starting'
>> filenames to sort to the bottom, and did a character reversal on them so that
>> when you reverse the sort, it always does the right thing. :) (sort of a
>> Schwartzian Transform) .. normally I was creating this on the fly while
>> importing the data from my flat-file, and either padding it with the rating,
>> or not, depending whether I wanted to sort by title, or by rating and then
>> title. 
>> 
>> What with the SQL ability to sort WHILE reading the data, it may not be
>> necessary, but it seems to be the only way I can get the numerics to sort to
>> the bottom always, and still remain in the correct order otherwise.
>> 
>> 
>> Why is it treating it like a numeric despite the obviousness that it is a
>> string? after looking at some other sort algorithms recently, I thought to
>> myself "wouldn't it be simpler to write it as this?"
>> {
>> $a <=> $b 
>> || 
>> $a cmp $b 
>> }
>> 
>> ... or am I off-base here? Do you now have a better way to determine if a
>> field value is numeric or string?
>> 
>> Your thoughts (and time) would be appreciated.
>> 
>> I hope I haven't included too much information, but I thought being thorough
>> and giving a full explanation while showing what I tried was better than a
>> half-assed question. :)
 

> Hi, Scott,
> 
> I highly agree with you, that the RE that determines whether
> a column contains a number should be changed. Any suggestions,
> besides ^[+-]\d+$, possibly including floats?
> 
> Thanks,
> 
> Jochen

I mailed Jochen back and indicated that I'd be posting this query to the
MacPerl lists and to comp.lang.perl.misc as well in search of a better
answer.. responses welcome. I'm stumped. :)

*muttergrumbleregexes*

-- 
Scott R. Godin            | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |    web : http://www.webdragon.net/


Reply via email to