Sorting in categories alphabetically & by numerical valu

Archive of notes and cross input on Dev versions of Coranto (1.25.1 and Older)

Moderators: Dale Ray, SrNupsen, Bluetooth, Jackanape

Sorting in categories alphabetically & by numerical valu

Postby jipskin » Tue Aug 06, 2002 5:05 am

I have a subroutine attached to each of my profiles that sorts each news item alphabetically by its contents (I'm using newspro to list inventory on a website, not for news).

I have this subroutine (thanks to Mat from an earlier post):

sub NewsCatFilterAlpha {
my @NND = &NewsCatFilter(@_);
my @NNDsorted = map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map { [ $_, $_->{'newssubject'} ] } @NND;
return @NNDsorted;
}


The problem is that while it alphabetizes records that begin with letters perfectly, those that begin with numbers are arranged in ASCII order instead of by numerical value (for example, 99 comes after 10353, even though it is obviously a smaller number). I have a feeling this would be very simple to do if I knew CGI that well, so if anyone is willing to give me a hand I would really appreciate it :)

Oh, and if that is easy, this must be easy: I want to sort records in the following order:

Instead of 1-10 coming after 1, I would like 1-10 to be sorted before 1 (reverse dictionary order, instead of frustrate coming before frustrated, frustrated comes before frustrate). I'm not sure if this is easy to do or not, but if you can do it, it would really help me. This isn't as important to me as the correct numeric sorting, so don't break your balls working on this one.

Thanks,
Josh
jipskin
 
Posts: 1
Joined: Tue Aug 06, 2002 4:26 am

Sorting news in small text file

Postby slebleu » Tue Jul 13, 2004 2:13 am

Hi, I'm using this to sort my news list. But I would like to modify it. So it can produce small text file for each letter e.g. a.txt, b.txt ect...

sub NewsCatFilterAlpha {
my @NND = &NewsCatFilter(@_);
my @NNDsorted = map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map { [ $_, $_->{'newssubject'} ] } @NND;
return @NNDsorted;
}

But I don't understand what's in @NND and @NNDsorted. How can I read values from them? Here's what I have done so far:
sub DoFilterAlpha {
my @NND = &NewsCatFilter(@_);
my @NNDsorted = map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map { [ $_, ($_->{'newssubject'})[0] ] } @NND;

foreach $number ( @NND ) {
open (FILEHANDLE, ">>test".".txt") or die "no such file";
print FILEHANDLE $a->[1].",";
close (FILEHANDLE);
}
}

Can somebody help my in order to access the title of the news so I can write them in a file

Thanks
slebleu
 
Posts: 1
Joined: Tue Jul 13, 2004 2:00 am


Return to Coranto Development Archives -- 1.25.1 and Older

Who is online

Users browsing this forum: No registered users and 3 guests

cron