⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 internet services.mht

📁 Perl 编程技巧大全。适合初学者阅读。
💻 MHT
📖 第 1 页 / 共 4 页
字号:
<FONT color=3D#00cd00>"Can't send from STDIN: $!\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$ftp-&gt;get<FONT color=3D#00ffff>(</FONT>$remotefile, =
$localfile<FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't fetch $remotefile : $!\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$ftp-&gt;get<FONT color=3D#00ffff>(</FONT>$remotefile, =
*STDOUT<FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't fetch $remotefile: $!\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$ftp-&gt;cwd<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"/pub/perl/CPAN/images/g-rated"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#ff7f50>print</FONT> <FONT color=3D#00cd00>"I'm in the =
directory "</FONT>, $ftp-&gt;pwd<FONT color=3D#00ffff>()</FONT>, <FONT =
color=3D#00cd00>"\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>   $ftp-&gt;<FONT color=3D#98fb98>mkdir</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"/pub/gnat/perl"</FONT>, =
<FONT color=3D#cdcd00>1</FONT><FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't create /pub/gnat/perl recursively: =
$!\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#cdad00>@lines</FONT> =3D $ftp-&gt;ls<FONT =
color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"/pub/gnat/perl"</FONT><FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't get a list of files in /pub/gnat/perl: =
$!"</FONT><FONT color=3D#00ffff>;</FONT>
$ref_to_lines =3D $ftp-&gt;dir<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"/pub/perl/CPAN/src/latest.tar.gz"</FONT><FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't check status of latest.tar.gz: =
$!\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$ftp-&gt;quit<FONT color=3D#00ffff>()</FONT>    <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> <FONT =
color=3D#00cd00>"Couldn't quit.  Oh well.\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN984>Sending Mail</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT =
color=3D#b2dfee>Mail::Mailer</FONT><FONT color=3D#00ffff>;</FONT>

$mailer =3D Mail::Mailer-&gt;new<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"sendmail"</FONT><FONT color=3D#00ffff>);</FONT>
$mailer-&gt;<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>({</FONT> <FONT color=3D#00cd00>From</FONT>    =3D&gt; =
$from_address,
                <FONT color=3D#00cd00>To</FONT>      =3D&gt; =
$to_address,
                <FONT color=3D#00cd00>Subject</FONT> =3D&gt; $subject,
              <FONT color=3D#00ffff>})</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't open: $!\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> $mailer $body<FONT =
color=3D#00ffff>;</FONT>
$mailer-&gt;
<FONT color=3D#98fb98>close</FONT><FONT color=3D#00ffff>();</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>SENDMAIL, <FONT =
color=3D#00cd00>"|/usr/lib/sendmail -oi -t -odq"</FONT><FONT =
color=3D#00ffff>)</FONT>
                    <FONT color=3D#98fb98>or</FONT> <FONT =
color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"Can't fork for =
sendmail: $!\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> SENDMAIL &lt;&lt;<FONT =
color=3D#00cd00>"EOF"</FONT><FONT color=3D#00ffff>;</FONT>
From: User Originating Mail &lt;me\<FONT =
color=3D#cdad00>@host</FONT>&gt;
To: Final Destination &lt;you\<FONT =
color=3D#cdad00>@otherhost</FONT>&gt;
Subject: A relevant subject line

Body of the message goes here, in as many lines as you like.
EOF
<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>SENDMAIL<FONT color=3D#00ffff>)</FONT>     <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> <FONT =
color=3D#00cd00>"sendmail didn't close nicely"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$mailer =3D Mail::Mailer-&gt;new<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"sendmail"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$mailer =3D Mail::Mailer-&gt;new<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"mail"</FONT>, <FONT =
color=3D#00cd00>"/u/gnat/bin/funkymailer"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$mailer =3D Mail::Mailer-&gt;new<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"smtp"</FONT>, <FONT =
color=3D#00cd00>"mail.myisp.com"</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>eval</FONT> <FONT color=3D#00ffff>{</FONT>
    $mailer =3D Mail::Mailer-&gt;new<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"bogus"</FONT>, <FONT =
color=3D#00cd00>"arguments"</FONT><FONT color=3D#00ffff>);</FONT>
    <FONT color=3D#bebebe># ...
</FONT><FONT color=3D#00ffff>};</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$@<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#bebebe># the eval failed
</FONT>    <FONT color=3D#ff7f50>print</FONT> <FONT =
color=3D#00cd00>"Couldn't send mail: $@\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT>
    <FONT color=3D#bebebe># the eval succeeded
</FONT>    <FONT color=3D#ff7f50>print</FONT> <FONT color=3D#00cd00>"The =
authorities have been notified.\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$mailer-&gt;<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT> <FONT color=3D#00cd00>'From'</FONT>    =3D&gt; =
<FONT color=3D#00cd00>'Nathan Torkington &lt;gnat</FONT><FONT =
color=3D#cdad00>@frii</FONT><FONT color=3D#00cd00>.com&gt;'</FONT>,
               <FONT color=3D#00cd00>'To'</FONT>      =3D&gt; <FONT =
color=3D#00cd00>'Tom Christiansen &lt;tchrist</FONT><FONT =
color=3D#cdad00>@perl</FONT><FONT color=3D#00cd00>.com&gt;'</FONT>,
               <FONT color=3D#00cd00>'Subject'</FONT> =3D&gt; <FONT =
color=3D#00cd00>'The Perl Cookbook'</FONT> <FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> $mailer &lt;&lt;EO_SIG<FONT =
color=3D#00ffff>;</FONT>
Are we ever going to finish this book?
My wife is threatening to leave me.
She says I love EMACS more than I love her.
Do you have a recipe that can help me?

Nat
EO_SIG
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>$mailer<FONT color=3D#00ffff>)</FONT>            =
          <FONT color=3D#98fb98>or</FONT> <FONT =
color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"can't close mailer: =
$!"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>SENDMAIL, <FONT =
color=3D#00cd00>"|/usr/sbin/sendmail -oi -t -odq"</FONT><FONT =
color=3D#00ffff>)</FONT>
            <FONT color=3D#98fb98>or</FONT> <FONT =
color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"Can't fork for =
sendmail: $!\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> SENDMAIL &lt;&lt;<FONT =
color=3D#00cd00>"EOF"</FONT><FONT color=3D#00ffff>;</FONT>
From: Tom Christiansen &lt;tchrist\<FONT =
color=3D#cdad00>@perl</FONT>.com&gt;
To: Nathan Torkington &lt;gnat\<FONT =
color=3D#cdad00>@frii</FONT>.com&gt;
Subject: Re: The Perl Cookbook

<FONT color=3D#00ffff>(</FONT><FONT color=3D#cdcd00>1</FONT><FONT =
color=3D#00ffff>)</FONT> We will never finish the book.
<FONT color=3D#00ffff>(</FONT><FONT color=3D#cdcd00>2</FONT><FONT =
color=3D#00ffff>)</FONT> No man who uses EMACS is deserving of love.
<FONT color=3D#00ffff>(</FONT><FONT color=3D#cdcd00>3</FONT><FONT =
color=3D#00ffff>)</FONT> I recommend coq au vi.

tom
EOF
<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>SENDMAIL<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN987>Reading and Posting Usenet News =
Messages</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT =
color=3D#b2dfee>Net::NNTP</FONT><FONT color=3D#00ffff>;</FONT>

$server =3D Net::NNTP-&gt;new<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"news.host.dom"</FONT><FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't connect to news server: $@\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>(</FONT>$narticles, $first, $last, $name<FONT =
color=3D#00ffff>)</FONT> =3D $server-&gt;group<FONT =
color=3D#00ffff>(</FONT> <FONT color=3D#00cd00>"misc.test"</FONT> <FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't select misc.test\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
$headers  =3D $server-&gt;head<FONT color=3D#00ffff>(</FONT>$first<FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't get headers from article $first in =
$name\n"</FONT><FONT color=3D#00ffff>;</FONT>
$bodytext =3D $server-&gt;body<FONT color=3D#00ffff>(</FONT>$first<FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't get body from article $first in =
$name\n"</FONT><FONT color=3D#00ffff>;</FONT>
$article  =3D $server-&gt;article<FONT =
color=3D#00ffff>(</FONT>$first<FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't get article $first from =
$name\n"</FONT><FONT color=3D#00ffff>;</FONT>

$server-&gt;
postok<FONT color=3D#00ffff>()</FONT>

    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> =
<FONT color=3D#00cd00>"Server didn't tell me I could =
post.\n"</FONT><FONT color=3D#00ffff>;</FONT>

$server-&gt;post<FONT color=3D#00ffff>(</FONT> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#cdad00>@lines</FONT> <FONT =
color=3D#00ffff>]</FONT> <FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't post: $!\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>&lt;<FONT color=3D#cdcd00>0401</FONT><FONT =
color=3D#cdad00>@jpl</FONT>-devvax.JPL.NASA.GOV&gt;
<FONT color=3D#bebebe>#-----------------------------
</FONT>$server =3D Net::NNTP-&gt;new<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"news.mycompany.com"</FONT><FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Couldn't connect to news.mycompany.com: =
$@\n"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$grouplist =3D $server-&gt;
list<FONT color=3D#00ffff>()</FONT>

    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Couldn't fetch group list\n"</FONT><FONT =
color=3D#00ffff>;</FONT>

<FONT color=3D#ffa500>foreach</FONT> <FONT color=3D#9ac0cd>$group</FONT> =
<FONT color=3D#00ffff>(</FONT><FONT color=3D#ff7f50>keys</FONT> =
%$grouplist<FONT color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#ffa500>if</FONT> <FONT =
color=3D#00ffff>(</FONT>$grouplist-&gt;<FONT =
color=3D#00ffff>{</FONT>$group<FONT color=3D#00ffff>}</FONT>-&gt;<FONT =
color=3D#00ffff>[</FONT><FONT color=3D#cdcd00>2</FONT><FONT =
color=3D#00ffff>]</FONT> <FONT color=3D#98fb98>eq</FONT> <FONT =
color=3D#00cd00>'y'</FONT><FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#00ffff>{</FONT>
        <FONT color=3D#bebebe># I can post to $group
</FONT>    <FONT color=3D#00ffff>}</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#00ffff>(</FONT>$narticles, $first, $last, =
$name<FONT color=3D#00ffff>)</FONT> =3D $server-&gt;group<FONT =
color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>"comp.lang.perl.misc"</FONT><FONT =
color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't select comp.lang.perl.misc\n"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#cdad00>@lines</FONT> =3D $server-&gt;article<FONT =
color=3D#00ffff>(</FONT>$message_id<FONT color=3D#00ffff>)</FONT>
    <FONT color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> =
<FONT color=3D#00cd00>"Can't fetch article $message_id: =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -