Article View: news.software.readers
Article #46151Re: [slrn] Saving new/unread articles?
From: meo... Fluffy
Date: Sat, 30 Jan 1999 00:00
Date: Sat, 30 Jan 1999 00:00
43 lines
2163 bytes
2163 bytes
John E. Davis <da...@space.mit.edu> wrote:
> [...]
> >> > @articles = sort grep(/\d+/, readdir(dir));
> >
> >> Does the sort perform a numerical sort or an alphabetic sort?
> >> Does it make a difference? Naively, I would say yes.
> >
> >it gets all the files that are numeric only (ie. the articles) and sorts
> >those numerically
>
> I am skeptical about this. Isn't grep passing a list of strings
> that happen to contain integers to sort? What if I really wanted the
> strings to be sorted alphabetically and not numerically?
You're right, the sort used is incorrect.
fluffy:~$ cat f.pl
#!/usr/bin/perl -w
use strict;
my (@articles, @foo);
@foo=(1,2,3,4,5,6,7,8,9,10,11);
# alpha sort
@articles = sort grep(/\d+/, @foo);
for my $bar (@articles) { print "$bar "; }
print "\n---\n";
# numeric sort
@articles = sort {$a <=> $b} grep(/\d+/, @foo);
for my $bar (@articles) { print "$bar "; }
print "\n";
fluffy:~$ f.pl
1 10 11 2 3 4 5 6 7 8 9
---
1 2 3 4 5 6 7 8 9 10 11
--
"Meow." --me
Technical Details
Message-ID:
<78ti7n$2h4@meow.invalid>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mailReferences:
<CBdq2.114$yk7.461@news.get2net.dk> <36aaa085.0@news.kosone.com> <RONq2.59$sG5.292@news.get2net.dk> <36ae8466.0@news.kosone.com> <slrn7atdac.iie.davis@aluche.mit.edu> <36b23651.0@news.kosone.com> <slrn7b4hkg.sse.davis@aluche.mit.edu>Show Full Headers
Complete Article Headers
Message-ID: <78ti7n$2h4@meow.invalid> Subject: Re: [slrn] Saving new/unread articles? Date: Sat, 30 Jan 1999 00:00:00 +0000 From: meo...@banet.net (Fluffy) References: <CBdq2.114$yk7.461@news.get2net.dk> <36aaa085.0@news.kosone.com> <RONq2.59$sG5.292@news.get2net.dk> <36ae8466.0@news.kosone.com> <slrn7atdac.iie.davis@aluche.mit.edu> <36b23651.0@news.kosone.com> <slrn7b4hkg.sse.davis@aluche.mit.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mail X-Deja-AN: 438533447 Mail-Copies-To: never X-Notice: should be reported to postm...@ibm.net X-P-36: modulator/space; kaboom=earth-shattering X-Complaints-To: postm...@ibm.net X-Trace: 30 Jan 1999 00:03:07 GMT, 129.37.108.61 Organization: If one may meow, all may meow. X-URL: http://members.tripod.com/~gerglery/ X-P-Meow: Meow Cancel-Lock: sha1:oUIZFhWIw5rrFBI3lRm2uPF/nVQ= Newsgroups: news.software.readers,alt.lang.s-lang