Article View: news.software.readers
Article #46140Re: [slrn] Saving new/unread articles?
From: 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
*-------------------------------------
Technical Details
Message-ID:
<36b23651.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-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>Show Full Headers
Complete Article Headers
Message-ID: <36b23651.0@news.kosone.com> Subject: Re: [slrn] Saving new/unread articles? Date: Fri, 29 Jan 1999 00:00:00 +0000 From: to...@myspleen.kos.net (tony summerfelt) 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> 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: 438500041 X-Trace: newsfeed.slurp.net 917649023 199.246.3.130 (Fri, 29 Jan 1999 16:30:23 CDT) Organization: Kingston Online Services User-Agent: slrn/0.9.5.4 (UNIX) Reply-To: to...@myspleenkos.net NNTP-Posting-Date: Fri, 29 Jan 1999 16:30:23 CDT Newsgroups: news.software.readers,alt.lang.s-lang