🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #46107

Re: [slrn] Saving new/unread articles?

#46107
From: Hrvoje Niksic
Date: Wed, 27 Jan 1999 00:00
108 lines
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.
Technical Details
Message-ID: <87zp75f3jy.fsf@pc-hrvoje.srce.hr>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mail
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>

Show Full Headers
Complete Article Headers
Message-ID: <87zp75f3jy.fsf@pc-hrvoje.srce.hr>
Subject: Re: [slrn] Saving new/unread articles?
Date: Wed, 27 Jan 1999 00:00:00 +0000
From: Hrvoje Niksic <hni...@srce.hr>
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: 437457418
Mail-Copies-To: never
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: ne...@news.carnet.hr
X-Trace: bagan.srce.hr 917430597 21817 161.53.2.132 (27 Jan 1999 09:49:57 GMT)
X-Face: &{dT~)Pu6V<0y?>3p$;@vh\`C7xB~A0T-J%Og)J,@-1%q6Q+, gs<-9M#&`I8cJp2b1{vPE|~+JE+gx;a7%BG{}nY^ehK1"q#rG O,Rn1A_Cy%t]V=Brv7h<L@)<XGh#XroV6xQg$VA8K
Organization: SRCE Zagreb, Croatia
X-Attribution: Hrvoje
User-Agent: Gnus/5.070072 (Pterodactyl Gnus v0.72) XEmacs/21.2(beta8) (Artemis)
Mime-Version: 1.0
NNTP-Posting-Date: 27 Jan 1999 09:49:57 GMT
Newsgroups: news.software.readers,alt.lang.s-lang