Thread View: news.software.readers
16 messages
16 total messages
Started by to... tony summerfelt
Sat, 23 Jan 1999 00:00
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Sat, 23 Jan 1999 00:00
Date: Sat, 23 Jan 1999 00:00
158 lines
4938 bytes
4938 bytes
On Sat, 23 Jan 1999 06:02:10 GMT, ras2 wrote:
> Odd situation: For rather obscure reasons, I want to save all
> new posts in a certain group to a file, preferably without
> even entering the group, i.e. I need to archive the posts,
i use this macro that i modified from another in the docs iirc. the perl
program following it will save them to the appropriate directories (assuming
they exist (you could change the perl program to make them if you like. i'm
using slrnpull so i don't have to worry about that, but the rkive.sl macro
will work without slrnpull...
you'd have to make sure your directories between the two programs are in
sync...
you'll need another macro to make them all read once all the articles are
re-written...
this will archive your groups:
==========================================================================
%rkive.sl
define append_to_file ()
{
ERROR_BLOCK
{
_clear_error ();
}
set_input_string ("~/unread.nws");
call ("save");
}
define save_unread ()
{
if (is_group_mode ()) return;
variable msgid = extract_article_header ("Message-ID");
variable is_collapsed = is_thread_collapsed ();
EXIT_BLOCK
{
set_input_string (msgid);
call ("locate_header_by_msgid");
if (is_collapsed) collapse_thread ();
}
call ("header_bob");
do
{
if (is_thread_collapsed ())
{
uncollapse_thread ();
loop (thread_size () - 1)
{
!if (get_header_flags () & HEADER_READ)
append_to_file ();
() = header_down (1);
}
!if (get_header_flags () & HEADER_READ)
append_to_file ();
collapse_thread ();
}
else
!if (get_header_flags () & HEADER_READ)
append_to_file ();
}
while (header_down (1));
}
define loop_groups ()
{
call ("bob");
do
{
call ("select_group");
save_unread ();
call ("quit");
}
while (group_down_n (1));
}
definekey ("loop_groups", "R", "group");
==========================================================================
#!/usr/bin/perl
#unrkive.pl this will unarchive.
$basedir="/var/spool/news/";
$newsarchive="~/unread.nws";
$count=0;
open (unread,"$newsarchive") || die "\"$newsarchive\" -- $!";
print "\nrestoring unread news from $newsarchive\n\n";
while(<unread>)
{
$from=$_ if /^from/i;
if (/^newsgroups/i)
{
$count++;
$newsdir=$_;
$newsgroups=$_;
$newsdir=~s/\./\//g;
$newsdir=~s/^newsgroups:\s+//i;
$newsdir=~s/\s+$//;
@newsdir=split(/,/,$newsdir);
foreach $newsdir (@newsdir)
{
$newsdir=$basedir.$newsdir;
if (-d $newsdir)
{
print "$count: [newsgroup] $newsdir\n";
# get list of existing articles
opendir(dir, $newsdir);
@articles = sort grep(/\d+/, readdir(dir));
closedir(dir);
# set next article number
$min=$articles[0];
@articles=reverse(@articles);
$max=$articles[0];
$article=$max;
$article++;
open (minmax,">$newsdir/\.minmax")
|| die "\".minmax\" -- $!";
print minmax "$min $max\n";
truncate("$newsdir/\.overview",0);
open (msgline,">$newsdir/$article")
|| die "\"$article\" -- $!";
print msgline "$from";
}
}
}
print msgline $_;
}
print "\n$count articles restored from $newsarchive\n";
--
t
*-------------------------------------------------------------------------
| origin: ...the vented spleen kingston on (613-544-9332) 1:249/139
|
| `you want a toe? i can get you a toe'
|
| take myspleen out to reply via email
*-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Tue, 26 Jan 1999 00:00
Date: Tue, 26 Jan 1999 00:00
27 lines
1673 bytes
1673 bytes
On Sun, 24 Jan 1999 23:13:53 GMT, ras2 wrote: > Thank you. This is almost exactly what I was looking for. it seems to be a feature that slrn is missing. a friend said in passing that he missed it from his yarn days, so i thought how hard could it be? i learned to use slang in the process. > I'm using slrnpull too, so that's not a problem (assuming I'll ever > figure out how to actually use Perl scripts). i did it in perl because i knew it was only going to take a few minutes. i don't know if it can be done in slang... anyone? -- t *------------------------------------------------------------------------- | origin: ...the vented spleen kingston on (613-544-9332) 1:249/139 | | `you want a toe? i can get you a toe' | | take myspleen out to reply via email *-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: da... John E. Davis
Date: Wed, 27 Jan 1999 00:00
Date: Wed, 27 Jan 1999 00:00
139 lines
5186 bytes
5186 bytes
On 26 Jan 1999 22:13:42 -0500, tony summerfelt <to...@myspleen.kos.net>
wrote:
>i did it in perl because i knew it was only going to take a few minutes. i
>don't know if it can be done in slang...
>
>anyone?
I am sure that it could be done, but since I do not read nor write
perl, I do not fully understand the script. I have a few questions:
>#!/usr/bin/perl
>#unrkive.pl this will unarchive.
>
>$basedir="/var/spool/news/";
>$newsarchive="~/unread.nws";
>$count=0;
>
>open (unread,"$newsarchive") || die "\"$newsarchive\" -- $!";
I assume that this opens the file in read-only mode and makes
`unread' the file descriptor. Also, providing support for the `~'
character is nice, but what if there really is a directory called
`~'? How does one pervent perl from performing the expansion on
`~'?
>print "\nrestoring unread news from $newsarchive\n\n";
Where does this message go? stdout or stderr?
>while(<unread>)
>{
What happens if there is a read error? Will the loop terminate?
How do you distinguish an I/O error from EOF?
> $from=$_ if /^from/i;
Is `$_' the line that was read in from the file? It is clear that
$_ is getting assigned to `from' if a certain pattern matched.
Does the pattern match all of the following?
from foo
fromfoo
From: foo
Fromfoo
Fromfoo
If so, is this what you really meant? Also, does `i' specify
case-insensitive matching?
> if (/^newsgroups/i)
> {
> $count++;
> $newsdir=$_;
> $newsgroups=$_;
> $newsdir=~s/\./\//g;
> $newsdir=~s/^newsgroups:\s+//i;
> $newsdir=~s/\s+$//;
> @newsdir=split(/,/,$newsdir);
I am not sure what is happening here. The intent seems to create
an array `newsdir' of newsgroups with `.' replaced by `/'. Does
this handle continuation lines? In S-Lang, I would use
newsdir = strtrim (newsgroups [[11:]]);
while (str_replace (newsdir, ".", "/"))
newsdir = ();
newsdir = strchop (newsdir, ',', 0);
to create an array of newsgroup directory names. I should add a
more consise intrinsic function to perform the replacement
operation.
> foreach $newsdir (@newsdir)
> {
> $newsdir=$basedir.$newsdir;
Is the `.' a string concatenation operator?
> if (-d $newsdir)
> {
> print "$count: [newsgroup] $newsdir\n";
> # get list of existing articles
>
> opendir(dir, $newsdir);
> @articles = sort grep(/\d+/, readdir(dir));
> closedir(dir);
Does the sort perform a numerical sort or an alphabetic sort?
Does it make a difference? Naively, I would say yes.
> # set next article number
> $min=$articles[0];
> @articles=reverse(@articles);
> $max=$articles[0];
> $article=$max;
> $article++;
>
> open (minmax,">$newsdir/\.minmax")
> || die "\".minmax\" -- $!";
> print minmax "$min $max\n";
> truncate("$newsdir/\.overview",0);
Currently, S-Lang does not support truncate. However, you can
probably use:
define truncate (file)
{
() = fopen (file, "w");
}
> open (msgline,">$newsdir/$article")
> || die "\"$article\" -- $!";
> print msgline "$from";
> }
The above fragment confuses me, particularly since you are looping
over all newsgroup directories. If there is more than one
newsgroup directory, then won't you be generating partial files in
all but the last directory?
> }
> }
> print msgline $_;
It is not clear to me what happens when msgline has not been
assigned a value. It seems to me that the first time through the
loop, before a newsgroup line is encountered, then the value of
msgline will not be valid. What happens in this case? Does perl
silently carry on?
Once I understand the perl code, I will attempt to write something
equivalent in S-Lang. At there very least it would indicate where
the language needs improved.
Thanks,
--John
Re: [slrn] Saving new/unread articles?
Author: Hrvoje Niksic
Date: Wed, 27 Jan 1999 00:00
Date: Wed, 27 Jan 1999 00:00
108 lines
4480 bytes
4480 bytes
da...@space.mit.edu (John E. Davis) writes:
> I am sure that it could be done, but since I do not read nor write
> perl, I do not fully understand the script.
I can answer the Perl questions.
> >$newsarchive="~/unread.nws";
[...]
> >open (unread,"$newsarchive") || die "\"$newsarchive\" -- $!";
>
> I assume that this opens the file in read-only mode and makes
> `unread' the file descriptor. Also, providing support for the
> `~' character is nice, but what if there really is a directory
> called `~'? How does one pervent perl from performing the
> expansion on `~'?
Perl doesn't do expansion on `~'. I don't think Toby actually tested
this.
> >print "\nrestoring unread news from $newsarchive\n\n";
>
> Where does this message go? stdout or stderr?
stdout. Sending to stderr would be:
print STDERR "..."
or using `select STDERR' all the prints would go to stderr, unless
overrided explicitly.
> >while(<unread>)
> >{
>
> What happens if there is a read error? Will the loop terminate?
Yes, and Perl will die.
> How do you distinguish an I/O error from EOF?
The documentation is not clear on this, but I think Perl will die in
case of such an error. However, it should be possible to trap errors
By using read() explicitly, if you need that kind of error recovery.
> > $from=$_ if /^from/i;
>
> Is `$_' the line that was read in from the file?
Yes. `while (<unread>)' is equivalent to `while defined ($_ = <unread>)'.
> Does the pattern match all of the following?
>
> from foo
> fromfoo
> From: foo
> Fromfoo
> Fromfoo
The pattern matches all strings that begin with `from',
case-insensitively. I don't know if that's what he wants.
> If so, is this what you really meant? Also, does `i' specify
> case-insensitive matching?
>
> > if (/^newsgroups/i)
> > {
> > $count++;
> > $newsdir=$_;
> > $newsgroups=$_;
> > $newsdir=~s/\./\//g;
> > $newsdir=~s/^newsgroups:\s+//i;
> > $newsdir=~s/\s+$//;
> > @newsdir=split(/,/,$newsdir);
>
> I am not sure what is happening here. The intent seems to
> create an array `newsdir' of newsgroups with `.' replaced by
> `/'. Does this handle continuation lines?
It doesn't. Not handling continuation lines is a typical fault with
Perl programming.
> > foreach $newsdir (@newsdir)
> > {
> > $newsdir=$basedir.$newsdir;
>
> Is the `.' a string concatenation operator?
Yes. It is often used in conjunction with `=', so the often-seen
expression `$foo .= $bar' does what you'd expect.
> > if (-d $newsdir)
> > {
> > print "$count: [newsgroup] $newsdir\n";
> > # get list of existing articles
> >
> > opendir(dir, $newsdir);
> > @articles = sort grep(/\d+/, readdir(dir));
> > closedir(dir);
>
> Does the sort perform a numerical sort or an alphabetic sort?
Alphabetically. To sort numerically, you should use:
@articles = sort { $a <=> $b } (grep /\d+/, readdir (dir));
<=> is the numerical comparison operator.
Re: [slrn] Saving new/unread articles?
Author: da... John E. Davis
Date: Fri, 29 Jan 1999 00:00
Date: Fri, 29 Jan 1999 00:00
51 lines
3195 bytes
3195 bytes
On 29 Jan 1999 17:29:37 -0500, tony summerfelt <to...@myspleen.kos.net> wrote: >> Also, providing support for the `~' >> character is nice, but what if there really is a directory called >> `~'? How does one pervent perl from performing the expansion on >> `~'? > >i would think that if there were a directory called `~' then it would be a >problem on the linux command line and not just any program that used it in a >directory name? i think perl understands unix `home' directories. > >i just tried to create a `~' directory on my account and because it's my >`home'directory it already exists, and therefore wouldn't let me. It depends upon your shell. For example, the bourne shell does not understand the `~' variable, nor do many other programs. This means that it is easy to create files or directories called `~'. [...] >> > @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? [...] >the only reason that i did it this way, is that i couldn't figure out how to >actually delete read articles physically from the directory. had i figured >that out, i would have tried to do it in s-lang. A file may be deleted using the `remove' intrinsic function. >once i had the unread messages archived, i was eager to get them written >back to the directories, and perl was the quickest way to do it Perhaps I am missing something here. When you read an article using slrn, that article does not get deleted from the slrnpull spool directory. It simple gets marked as `read' in the .newsrc file. So, when you archive a file from within slrn (via a macro, or otherwise), the file does not get removed. So, after they have been archive I do not understand why you re-create them in the spool directory. --John
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Fri, 29 Jan 1999 00:00
Date: Fri, 29 Jan 1999 00:00
155 lines
6244 bytes
6244 bytes
On 27 Jan 1999 06:42:02 GMT, John E. Davis wrote:
> I am sure that it could be done, but since I do not read nor write
> perl, I do not fully understand the script. I have a few questions:
bear in mind that i'm far from a perl/linux expert, but i'll try to answer
to the best of my knowledge:
> I assume that this opens the file in read-only mode and makes
> `unread' the file descriptor.
yes
> Also, providing support for the `~'
> character is nice, but what if there really is a directory called
> `~'? How does one pervent perl from performing the expansion on
> `~'?
i would think that if there were a directory called `~' then it would be a
problem on the linux command line and not just any program that used it in a
directory name? i think perl understands unix `home' directories.
i just tried to create a `~' directory on my account and because it's my
`home'directory it already exists, and therefore wouldn't let me.
i meant the script to be used system wide...
> Where does this message go? stdout or stderr?
stdout. all perl output defaults to stdout, and all perl error output
defaults to stderr
> What happens if there is a read error? Will the loop terminate?
> How do you distinguish an I/O error from EOF?
good question. i should probably lock the file before doing anything with
it. but it WAS a quick and dirty program :)
> Is `$_' the line that was read in from the file?
$_ is a default variable, numerous perl functions read/write it.
> Does the pattern match all of the following?
>
> from foo
> fromfoo
> From: foo
> Fromfoo
> Fromfoo
all are matched
> If so, is this what you really meant? Also, does `i' specify
> case-insensitive matching?
yes
> > if (/^newsgroups/i)
> > {
> > $count++;
> > $newsdir=$_;
> > $newsgroups=$_;
> > $newsdir=~s/\./\//g;
> > $newsdir=~s/^newsgroups:\s+//i;
> > $newsdir=~s/\s+$//;
> > @newsdir=split(/,/,$newsdir);
>
> I am not sure what is happening here. The intent seems to create
> an array `newsdir' of newsgroups with `.' replaced by `/'. Does
> this handle continuation lines?
it reads the `newsgroups' line. parses the line into all the newsgroups
listed. changes the `.' to `/' strips leading and ending spaces. puts all
the news `directories' into an array. i believe it will handle continuation.
i'm not sure...
> >$newsdir=$basedir.$newsdir;
> Is the `.' a string concatenation operator?
yes
> > @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
> Currently, S-Lang does not support truncate. However, you can
> probably use:
that's the route i was going to take.
> > open (msgline,">$newsdir/$article")
> > || die "\"$article\" -- $!";
> > print msgline "$from";
> > }
> The above fragment confuses me, particularly since you are looping
> over all newsgroup directories. If there is more than one
> newsgroup directory, then won't you be generating partial files in
> all but the last directory?
i had to save the `from' line earlier, here i'm printing it to the article.
> > print msgline $_;
> It is not clear to me what happens when msgline has not been
> assigned a value.
the `open(msgline,...' line opens the article with `msgline' as the file
handle. the print msgline $_ just prints the rest of the file opened with
the `unread' file handle. the earlier `foreach $newsdir (@newsdir)' cycles
through all the newsgroups directories and writes the entire article in each
one. seems to handle crossposts ok...
> It seems to me that the first time through the
> loop, before a newsgroup line is encountered, then the value of
> msgline will not be valid.
msgline is just the file handle. it's valid until it's closed or opened
again. i should have a close(msgline) to be aesthetic, but i take all
the perl shortcuts i can...
> Once I understand the perl code, I will attempt to write something
> equivalent in S-Lang. At there very least it would indicate where
> the language needs improved.
the only reason that i did it this way, is that i couldn't figure out how to
actually delete read articles physically from the directory. had i figured
that out, i would have tried to do it in s-lang.
once i had the unread messages archived, i was eager to get them written
back to the directories, and perl was the quickest way to do it
i really like S-lang, more file operations and tests would be nice. ie. like
perl or bash uses...
perl is a nice `glue' language, and that's what i used here.
--
t
*-------------------------------------------------------------------------
| origin: ...the vented spleen kingston on (613-544-9332) 1:249/139
|
| `you want a toe? i can get you a toe'
|
| take myspleen out to reply via email
*-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: da... John E. Davis
Date: Sat, 30 Jan 1999 00:00
Date: Sat, 30 Jan 1999 00:00
16 lines
1765 bytes
1765 bytes
On Sat, 30 Jan 1999 22:09:59 GMT, ras2 <remov...@gmx.net> wrote: >I thought of just setting the expire of this particular group to two >weeks or so, but once the number of posts gets to around 800, it slows >the downloads down too much (takes a long time to write the overview, I >assume). I'm paying for my online time by the second, so the longer I'm >online, the higher my phonebill will be (and it's high enough already). I suspect that the problem is with the server. My guess is that the server has detected the sucking feed and purposely delays its response. I am sure that if you run `top', you will find that slrnpull is sleeping most of the time and consumes very little CPU. --John
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Sat, 30 Jan 1999 00:00
Date: Sat, 30 Jan 1999 00:00
66 lines
3537 bytes
3537 bytes
On 29 Jan 1999 23:39:04 GMT, John E. Davis wrote: > It depends upon your shell. For example, the bourne shell does not i'm using bash v2.01.0 here. i get a `permission denied' error. that's probably a good thing :) > understand the `~' variable, nor do many other programs. This means > that it is easy to create files or directories called `~'. i have the full path name in my own version of the program, i just threw in the `~' when posting. i didn't realize it would be a potential problem... > >> > @articles = sort grep(/\d+/, readdir(dir)); > >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 the /\d+/ matches only filenames with one or more digits. in a newsgroup directory these will probably only be articles (i made a general assumption here). > strings to be sorted alphabetically and not numerically? i just wanted the list of articles, and figured that sorting them would be done numerically. is there a need to sort them alphabetecally? > A file may be deleted using the `remove' intrinsic function. i looked at that but IIRC, i thought it only removed from slrn's `internal' list of them, and not physically from the directory. that was really my only barrier as far as i could see > So, after they have been archive I do not understand why you re-create > them in the spool directory. it was a request from a friend here. he originally wanted to just delete the the read (or marked as read) articles. my misunderstanding of the `remove' instrinsic function led me to the perl solution. we are using drives with limited space (my linux setup is sitting on a 450meg hd. i don't know how my friend does it, but what i do when drive space gets a bit tight, is archive the unread articles run slrnpull in expire mode (i use 0 1 for defaults). this way i have just one day's (or none if i deleted the articles manually) articles, plus the unread articles. the perl program worked until i figured out the S-lang version. it looks like i have enough information now to do just that. i don't know how i missed the `remove' explanation in the docs... -- t *------------------------------------------------------------------------- | origin: ...the vented spleen kingston on (613-544-9332) 1:249/139 | | `you want a toe? i can get you a toe' | | take myspleen out to reply via email *-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: 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
Re: [slrn] Saving new/unread articles?
Author: Hrvoje Niksic
Date: Sun, 31 Jan 1999 00:00
Date: Sun, 31 Jan 1999 00:00
21 lines
1902 bytes
1902 bytes
to...@myspleen.kos.net (tony summerfelt) writes: > > Also, providing support for the `~' > > character is nice, but what if there really is a directory called > > `~'? How does one pervent perl from performing the expansion on > > `~'? > > i would think that if there were a directory called `~' then it > would be a problem on the linux command line and not just any > program that used it in a directory name? i think perl understands > unix `home' directories. It doesn't. Try it. > i just tried to create a `~' directory on my account and because > it's my `home'directory it already exists, and therefore wouldn't > let me. mkdir "~"
Re: [slrn] Saving new/unread articles?
Author: Hrvoje Niksic
Date: Sun, 31 Jan 1999 00:00
Date: Sun, 31 Jan 1999 00:00
34 lines
2328 bytes
2328 bytes
to...@myspleen.kos.net (tony summerfelt) writes:
> > >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
>
> the /\d+/ matches only filenames with one or more digits.
Yes, but they will still be sorted alphabetically. For instance, 100
will come out "greater" than 5.
> > strings to be sorted alphabetically and not numerically?
>
> i just wanted the list of articles, and figured that sorting them
> would be done numerically. is there a need to sort them
> alphabetecally?
You misunderstood David's question.
David: Aren't the strings sorted alphabetically here?
You: No, they are sorted numerically.
David: That's a weird way for "sort" to behave; what if I *wanted* an
alphabetical sort?
You: Why would you want that?
The correct answer is above: no, sort will not sort them numerically
by default. This has been pointed out by others, too.
Re: [slrn] Saving new/unread articles?
Author: da... John E. Davis
Date: Mon, 01 Feb 1999 00:00
Date: Mon, 01 Feb 1999 00:00
27 lines
1652 bytes
1652 bytes
On 1 Feb 1999 14:31:06 -0500, tony summerfelt <to...@myspleen.kos.net>
wrote:
>all that piece of code was supposed to do is get the highest article number
>and increment it for the next restored article. and, of course, the number
>will be used to write the .minmax file...
Suppose that the list of files consist of the strings:
"1" "2" "101" "5"
If sorted alphabetically, you will get the order:
1
101
2
5
But if sorted numerically, you will get:
1
2
5
101
--John
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Mon, 01 Feb 1999 00:00
Date: Mon, 01 Feb 1999 00:00
27 lines
1916 bytes
1916 bytes
On 31 Jan 1999 04:28:31 +0100, Hrvoje Niksic wrote: > Yes, but they will still be sorted alphabetically. For instance, 100 > will come out "greater" than 5. isn't that what we want, 100 > 5? > The correct answer is above: no, sort will not sort them numerically > by default. This has been pointed out by others, too. all that piece of code was supposed to do is get the highest article number and increment it for the next restored article. and, of course, the number will be used to write the .minmax file... i hate to sound obtuse, but i think i'm missing the point here :( -- t *------------------------------------------------------------------------- | origin: ...the vented spleen kingston on (613-544-9332) 1:249/139 | | `you want a toe? i can get you a toe' | | take myspleen out to reply via email *-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: Hrvoje Niksic
Date: Tue, 02 Feb 1999 00:00
Date: Tue, 02 Feb 1999 00:00
25 lines
2216 bytes
2216 bytes
to...@myspleen.kos.net (tony summerfelt) writes: > On 31 Jan 1999 04:28:31 +0100, Hrvoje Niksic wrote: > > > Yes, but they will still be sorted alphabetically. For instance, 100 > > will come out "greater" than 5. > > isn't that what we want, 100 > 5? Under an alphabetical soer, 100 would come out "smaller" than 5 (the above was a lapsus.) > > The correct answer is above: no, sort will not sort them numerically > > by default. This has been pointed out by others, too. > > all that piece of code was supposed to do is get the highest article > number and increment it for the next restored article. and, of > course, the number will be used to write the .minmax file... > > i hate to sound obtuse, but i think i'm missing the point here :( The point is that you can't use alphabetical sort to sort numbers, or vice versa.
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Tue, 02 Feb 1999 00:00
Date: Tue, 02 Feb 1999 00:00
22 lines
1703 bytes
1703 bytes
On 02 Feb 1999 15:54:26 +0100, Hrvoje Niksic wrote: > The point is that you can't use alphabetical sort to sort numbers, or > vice versa. see my post to mr. davis, i think the fix i posted is what's needed. i didn't think a sort would perform differently on just numbers... i learn something new everyday :) -- t *------------------------------------------------------------------------- | origin: ...the vented spleen kingston on (613-544-9332) 1:249/139 | | `you want a toe? i can get you a toe' | | take myspleen out to reply via email *-------------------------------------
Re: [slrn] Saving new/unread articles?
Author: to... tony summerfelt
Date: Tue, 02 Feb 1999 00:00
Date: Tue, 02 Feb 1999 00:00
37 lines
2188 bytes
2188 bytes
On 1 Feb 1999 22:40:48 GMT, John E. Davis wrote:
> But if sorted numerically, you will get:
ok, i get it now. i was (wrongly) assuming that perl would sort numbers
numerically. usually perl assumptions work, but not in this case. i DID say
i was a perl novice :)
this is the fix for the problem.
put this line near the top or bottom (wherever you put your subroutines)
sub numerically {$a <=> $b;}
and this bit:
opendir(dir, $newsdir);
@articles = sort grep(/\d+/, readdir(dir));
closedir(dir);
will now be:
opendir(dir, $newsdir);
@unsorted_articles = grep(/\d+/, readdir(dir));
@articles = sort numerically @unsorted_articles
closedir(dir);
--
t
*-------------------------------------------------------------------------
| origin: ...the vented spleen kingston on (613-544-9332) 1:249/139
|
| `you want a toe? i can get you a toe'
|
| take myspleen out to reply via email
*-------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads