📄 ch17_03.htm
字号:
<html><head><title>The News::Newsrc Module (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch17_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch18_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">17.3. The News::Newsrc Module</h2><p><a name="INDEX-2250" /><a name="INDEX-2251" /><a name="INDEX-2252" /><a name="INDEX-2253" />Most Unix-based newsreaders parse andextract your newsgroup information from a<em class="filename">.newsrc</em> file. This file contains an entry foreach newsgroup, with the name of the group and a comma-separated listof article numbers from 1 to the current article. The first entry inthe list shows articles that have been read; the remaining entrieslist unread articles. Each entry also has a colon (:) following thename if you are subscribed to that newsgroup, or an exclamation point(<tt class="literal">!</tt>) if you are currently unsubscribed.</p><p>To read a newsgroup, your newsreader needs to be connected to an NNTPserver. The newsreader then checks the <em class="filename">.newsrc</em>entry for that newsgroup to determine which articles youhaven't read, and displays the first unread article.You can then read the articles sequentially or select which articlesyou want to read. When you"catch-up" a newsgroup by markingall the articles as "read", or whenyou exit from the newsreader program, your<em class="filename">.newsrc</em> file is updated to reflect your activityduring that session.</p><p>The News::Newsrc module provides methods for managing your<em class="filename">.newsrc</em> file. Some of the functions it providesinclude letting you add, remove, or reorder newsgroups; subscribe toor unsubscribe from newsgroups; and mark articles as read or unmarkthem. Unless you tell it to rearrange the order of the newsgroups in<em class="filename">.newsrc</em>, News::Newsrc leaves the orderunchanged.</p><a name="perlnut2-CHP-17-SECT-3.1" /><div class="sect2"><h3 class="sect2">17.3.1. News::Newsrc Reference</h3><a name="INDEX-2254" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>new</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em> = new <em class="replaceable">News</em>::<em class="replaceable">Newsrc</em></pre><p><a name="INDEX-2254" />Constructor. Creates a new News::Newsrcobject that contains no newsgroups.</p></div><a name="INDEX-2255" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>add_group</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->add_group(<em class="replaceable">groupname</em>[, <em class="replaceable">options</em>])</pre><p><a name="INDEX-2255" />Adds newsgroup to<em class="filename">.newsrc</em>, as a subscribed group. Defaults toadding at the end. The arguments are:</p><dl><dt><i><em class="replaceable"><tt>groupname</tt></em></i></dt><dd>Name of the newsgroup to add.</p></dd><dt><i><em class="replaceable"><tt>options</tt></em></i></dt><dd>Hash with one entry, indicating where to put the newsgroup. Key is<tt class="literal">where</tt>, and possible values are:</p><dl><dt><b><tt class="literal">after =></tt> <em class="replaceable">group</em></b></dt><dd>Put immediately after newsgroup <em class="replaceable"><tt>group</tt></em>, orlast if <em class="replaceable"><tt>group</tt></em> is not there.</p></dd><dt><b><tt class="literal">alpha</tt></b></dt><dd>Put in alphabetical order.</p></dd><dt><b><tt class="literal">before =></tt> <em class="replaceable">group</em></b></dt><dd>Put immediately before newsgroup <em class="replaceable"><tt>group</tt></em>.</p></dd><dt><b><tt class="literal">first</tt></b></dt><dd>Put as first newsgroup.</p></dd><dt><b><tt class="literal">last</tt></b></dt><dd>Put as last newsgroup.</p></dd><dt><b><tt class="literal">number =></tt> <em class="replaceable">n</em></b></dt><dd>Put at position <em class="replaceable"><tt>n</tt></em>, where the firstposition is <tt class="literal">0</tt>. If position is negative, count fromthe end of the list backwards <em class="replaceable"><tt>n</tt></em> positions.</p></dd></dl></dd></dl></div><a name="INDEX-2256" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>del_group</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->del_group(<em class="replaceable">groupname</em>)</pre><p><a name="INDEX-2256" />Removes specified newsgroup<em class="replaceable"><tt>groupname</tt></em> from<em class="filename">.newsrc</em>.</p></div><a name="INDEX-2257" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>exists</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->exists(<em class="replaceable">groupname</em>)</pre><p><a name="INDEX-2257" />Returns true if newsgroup<em class="replaceable"><tt>groupname</tt></em> is in<em class="filename">.newsrc</em>.</p></div><a name="INDEX-2258" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>groups</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->groups( )</pre><p><a name="INDEX-2258" />Returns list of newsgroups in<em class="filename">.newsrc</em>. In scalar context, returns an arrayreference.</p></div><a name="INDEX-2259" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>load</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->load([<em class="replaceable">filename</em>])</pre><p><a name="INDEX-2259" />Loads newsgroups in<em class="replaceable"><tt>filename</tt></em> into<tt class="literal">$</tt><em class="replaceable"><tt>newsrc</tt></em>, replacing anynewsgroups that are already there. Defaults to<tt class="literal">$HOME/.newsrc</tt>.</p></div><a name="INDEX-2260" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>mark</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->mark(<em class="replaceable">groupname</em>, <em class="replaceable">article_number</em>[, <em class="replaceable">options</em>])</pre><p><a name="INDEX-2260" />Adds an article to the list fora specified newsgroup. Arguments are:</p><dl><dt><i><em class="replaceable"><tt>groupname</tt></em></i></dt><dd>Newsgroup to add an article to.</p></dd><dt><i><em class="replaceable"><tt>article_number</tt></em></i></dt><dd>Article number of the article to add.</p></dd><dt><i><em class="replaceable"><tt>options</tt></em></i></dt><dd>Hash. See description under <tt class="literal">add_group</tt>.</p></dd></dl></div><a name="INDEX-2261" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>marked</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->marked(<em class="replaceable">groupname</em>, <em class="replaceable">article_number</em>)</pre><p><a name="INDEX-2261" />Returns true if the newsgroupexists and contains the specified article. Arguments are:</p><dl><dt><i><em class="replaceable"><tt>groupname</tt></em></i></dt><dd>Group to report on</p></dd><dt><i><em class="replaceable"><tt>article_number</tt></em></i></dt><dd>Number of the article to verify</p></dd></dl></div><a name="INDEX-2262" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>marked_articles</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->marked_articles(<em class="replaceable">groupname</em>)</pre><p><a name="INDEX-2262" />Returns the list of articles ingroup <em class="replaceable"><tt>groupname</tt></em>. In scalar context,returns an array reference.</p></div><a name="INDEX-2263" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>mark_list</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">newsrc</em>->mark_list(<em class="replaceable">groupname</em>, \@<em class="replaceable"><tt>article_list</tt></em>[, <em class="replaceable">options</em>])</pre><p><a name="INDEX-2263" />Adds articles to the list for aspecified group. Arguments are:</p><dl><dt><i><em class="replaceable"><tt>groupname</tt></em></i></dt><dd>Group to add articles to.</p></dd><dt><b><tt class="literal">\@</tt><em class="replaceable">article_list</em></b></dt><dd>Reference to list of articles to add.</p></dd><dt><i><em class="replaceable"><tt>options</tt></em></i></dt><dd>Hash. See description under <tt class="literal">add_group</tt>.</p></dd>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -