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

📄 packages, libraries, and modules.mht

📁 Perl 编程技巧大全。适合初学者阅读。
💻 MHT
📖 第 1 页 / 共 5 页
字号:
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>Exporter =
DynaLoader<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#cdad00>@EXPORT_OK</FONT> =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT><FONT =
color=3D#98fb98>time</FONT><FONT color=3D#00ffff>);</FONT>
$VERSION =3D <FONT color=3D#00cd00>'0.01'</FONT><FONT =
color=3D#00ffff>;</FONT>
bootstrap <FONT color=3D#b2dfee>FineTime</FONT> $VERSION<FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#cdcd00>1</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
#include &lt;unistd.h&gt;
#include &lt;sys/time.h&gt;
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
</FONT>
MODULE =3D FineTime           PACKAGE =3D FineTime

double
<FONT color=3D#98fb98>time</FONT><FONT color=3D#00ffff>()</FONT>
    <FONT color=3D#ff7f50>CODE:</FONT>
        struct timeval tv<FONT color=3D#00ffff>;</FONT>
        gettimeofday<FONT color=3D#00ffff>(</FONT>&amp;tv,<FONT =
color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>);</FONT>
        RETVAL =3D tv.tv_sec + <FONT =
color=3D#00ffff>((</FONT>double<FONT color=3D#00ffff>)</FONT> =
tv.tv_usec<FONT color=3D#00ffff>)</FONT> / <FONT =
color=3D#cdcd00>1000000</FONT><FONT color=3D#00ffff>;</FONT>
    <FONT color=3D#ff7f50>OUTPUT:</FONT>
        RETVAL
<FONT color=3D#bebebe>#-----------------------------
#% make install
#mkdir ./blib/lib/auto/FineTime
#cp FineTime.pm ./blib/lib/FineTime.pm
#/usr/local/bin/perl -I/usr/lib/perl5/i686-linux/5.00403  =
-I/usr/lib/perl5
#/usr/lib/perl5/ExtUtils/xsubpp -typemap</FONT><FONT color=3D#43cd80> =
</FONT><FONT color=3D#bebebe>
#    /usr/lib/perl5/ExtUtils/typemap FineTime.xs
#FineTime.tc &amp;&amp; mv FineTime.tc FineTime.ccc -c -Dbool=3Dchar =
-DHAS_BOOL</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#    -O2-DVERSION=3D\"0.01\" -DXS_VERSION=3D\"0.01\" -fpic</FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#    -I/usr/lib/perl5/i686-linux/5.00403/CORE</FONT><FONT =
color=3D#43cd80>  </FONT><FONT color=3D#bebebe>
#FineTime.cRunning Mkbootstrap for FineTime ()
#chmod 644 FineTime.bs
#LD_RUN_PATH=3D"" cc -o blib/arch/auto/FineTime/FineTime.so</FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#    -shared -L/usr/local/lib FineTime.o
#chmod 755 blib/arch/auto/FineTime/FineTime.so
#cp FineTime.bs ./blib/arch/auto/FineTime/FineTime.bs
#chmod 644 blib/arch/auto/FineTime/FineTime.bs
#Installing /home/tchrist/perllib/i686-linux/./auto/FineTime/FineTime.so
#Installing /home/tchrist/perllib/i686-linux/./auto/FineTime/FineTime.bs
#Installing /home/tchrist/perllib/./FineTime.pm
#Writing /home/tchrist/perllib/i686-linux/auto/FineTime/.packlist
#Appending installation info to =
/home/tchrist/perllib/i686-linux/perllocal.pod
#-----------------------------
#% perl -I ~/perllib -MFineTime=3Dtime -le '1 while print time()' | head
#888177070.090978
#
#888177070.09132
#
#888177070.091389
#
#888177070.091453
#
#888177070.091515
#
#888177070.091577
#
#888177070.091639
#
#888177070.0917
#
#888177070.091763
#
#888177070.091864
#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN690>Documenting Your Module with =
Pod</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>#-----------------------------
#=3Dhead2 Discussion
#
#If we had a I&lt;.h&gt; file with function prototype declarations, we
#could include that, but since we're writing this one from scratch,
#we'll use the B&lt;-c&gt; flag to omit building code to translate any
#C&lt;#define&gt; symbols. The B&lt;-n&gt; flag says to create a module =
directory
#named I&lt;FineTime/&gt;, which will have the following files.
#-----------------------------
#=3Dfor troff
#.EQ
#log sub n (x) =3D { {log sub e (x)} over {log sub e (n)} }
#.EN
#-----------------------------
#=3Dfor later
#next if 1 .. ?^$?;
#s/^(.)/&gt;$1/;
#s/(.{73})........*/$1&lt;SNIP&gt;/;
#
#=3Dcut back to perl
#-----------------------------
</FONT>=3Dbegin comment

<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>!<FONT =
color=3D#98fb98>open</FONT><FONT color=3D#00ffff>(</FONT>FILE, =
$file<FONT color=3D#00ffff>))</FONT> <FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#00ffff>(</FONT>$opt_<FONT color=3D#ff7f50>q</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>  <FONT =
color=3D#bebebe>#)
</FONT>        <FONT color=3D#98fb98>warn</FONT> <FONT =
color=3D#00cd00>"$me: $file: $!\n"</FONT><FONT color=3D#00ffff>;</FONT>
        $Errors++<FONT color=3D#00ffff>;</FONT>
    <FONT color=3D#00ffff>}</FONT>
    <FONT color=3D#ffa500>next</FONT> <FONT =
color=3D#ff7f50>FILE</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>

$total =3D <FONT color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>;</FONT>
$matches =3D <FONT color=3D#cdcd00>0</FONT><FONT =
color=3D#00ffff>;</FONT>

=3Dend comment
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN693>Building and Installing a CPAN =
Module</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>#-----------------------------
#% gunzip Some-Module-4.54.tar.gz
#% tar xf Some-Module-4.54
#% cd Some-Module-4.54
#% perl Makefile.PL
#% make
#% make test
#% make install
#-----------------------------
#% gunzip MD5-1.7.tar.gz
#% tar xf MD5-1.7.tar
#% cd MD5-1.7
#% perl Makefile.PL</FONT><FONT color=3D#43cd80> </FONT><FONT =
color=3D#bebebe>
#Checking if your kit is complete...
#
#Looks good
#
#Writing Makefile for MD5
#
#% make
#mkdir ./blib
#
#mkdir ./blib/lib
#
#cp MD5.pm ./blib/lib/MD5.pm
#
#AutoSplitting MD5 (./blib/lib/auto/MD5)
#
#/usr/bin/perl -I/usr/local/lib/perl5/i386 ...
#
#...
#
#cp MD5.bs ./blib/arch/auto/MD5/MD5.bs
#
#chmod 644 ./blib/arch/auto/MD5/MD5.bsmkdir ./blib/man3
#
#Manifying ./blib/man3/MD5.3
#
#% make test
#PERL_DL_NONLAZY=3D1 /usr/bin/perl -I./blib/arch -I./blib/lib
#
#-I/usr/local/lib/perl5/i386-freebsd/5.00404 -I/usr/local/lib/perl5 =
test.pl
#
#1..14
#
#ok 1
#
#ok 2
#
#...
#
#ok 13
#
#ok 14
#
#% sudo make install
#Password:
#
#Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/
#
#    MD5.so
#
#Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/
#
#    MD5.bs
#
#Installing /usr/local/lib/perl5/site_perl/./auto/MD5/autosplit.ix
#
#Installing /usr/local/lib/perl5/site_perl/./MD5.pm
#
#Installing /usr/local/lib/perl5/man/man3/./MD5.3
#
#Writing /usr/local/lib/perl5/site_perl/i386-freebsd/auto/MD5/.packlist
#
#Appending installation info to /usr/local/lib/perl5/i386-freebsd/
#
#5.00404/perllocal.pod
#-----------------------------
# if you just want the modules installed in your own directory
#% perl Makefile.PL LIB=3D~/lib
#
# if you have your own a complete distribution
#% perl Makefile.PL PREFIX=3D~/perl5-private
#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN696>Example: Module Template</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>package</FONT> <FONT =
color=3D#b2dfee>Some::Module</FONT><FONT color=3D#00ffff>;</FONT>  <FONT =
color=3D#bebebe># must live in Some/Module.pm
</FONT>
<FONT color=3D#ffa500>use</FONT> <FONT =
color=3D#b2dfee>strict</FONT><FONT color=3D#00ffff>;</FONT>

<FONT color=3D#ffa500>require</FONT> <FONT =
color=3D#b2dfee>Exporter</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#ffa500>use</FONT> <FONT color=3D#b2dfee>vars</FONT>       =
<FONT color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>$VERSION =
<FONT color=3D#cdad00>@ISA</FONT> <FONT color=3D#cdad00>@EXPORT</FONT> =
<FONT color=3D#cdad00>@EXPORT_OK</FONT> <FONT =
color=3D#cdcd00>%EXPORT_TAGS</FONT><FONT color=3D#00ffff>);</FONT>

<FONT color=3D#bebebe># set the version for version checking
</FONT>$VERSION     =3D <FONT color=3D#cdcd00>0.01</FONT><FONT =
color=3D#00ffff>;</FONT>

<FONT color=3D#cdad00>@ISA</FONT>         =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>Exporter<FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#cdad00>@EXPORT</FONT>      =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>&amp;func1 =
&amp;func2 &amp;func4<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#cdcd00>%EXPORT_TAGS</FONT> =3D <FONT =
color=3D#00ffff>(</FONT> <FONT color=3D#00ffff>);</FONT>     <FONT =
color=3D#bebebe># eg: </FONT><FONT color=3D#00cd00>TAG</FONT><FONT =
color=3D#bebebe> =3D&gt; [ qw!name1 name2! ],
</FONT>
<FONT color=3D#bebebe># your exported package globals go here,
# as well as any optionally exported functions
</FONT><FONT color=3D#cdad00>@EXPORT_OK</FONT>   =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>$Var1 <FONT =
color=3D#cdcd00>%Hashit</FONT> &amp;func3<FONT color=3D#00ffff>);</FONT>

<FONT color=3D#ffa500>use</FONT> <FONT color=3D#b2dfee>vars</FONT> <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>$Var1 <FONT =
color=3D#cdcd00>%Hashit</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3

⌨️ 快捷键说明

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