Article View: news.software.readers
Article #46106Re: [slrn] Saving new/unread articles?
From: 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
Technical Details
Message-ID:
<slrn7atdac.iie.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-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>Show Full Headers
Complete Article Headers
Message-ID: <slrn7atdac.iie.davis@aluche.mit.edu> Subject: Re: [slrn] Saving new/unread articles? Date: Wed, 27 Jan 1999 00:00:00 +0000 From: da...@space.mit.edu (John E. Davis) 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> 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: 437427317 Organization: Center for Space Research User-Agent: slrn/0.9.5.4 (UNIX) Reply-To: da...@space.mit.edu Newsgroups: news.software.readers,alt.lang.s-lang