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

📄 perlio.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
characters.  (Which really is \s-1UTF\-8\s0 on \s-1ASCII\s0 machines, but isUTF-EBCDIC on \s-1EBCDIC\s0 machines.)  This allows any character perl canrepresent to be read from or written to the stream. The UTF-X encodingis chosen to render simple text parts (i.e.  non-accented letters,digits and common punctuation) human readable in the encoded file..SpHere is how to write your native data out using \s-1UTF\-8\s0 (or UTF-EBCDIC)and then read it back in..Sp.Vb 3\&        open(F, ">:utf8", "data.utf");\&        print F $out;\&        close(F);\&\&        open(F, "<:utf8", "data.utf");\&        $in = <F>;\&        close(F);.Ve.SpNote that this layer does not validate byte sequences. For readinginput, using \f(CW\*(C`:encoding(utf8)\*(C'\fR instead of bare \f(CW\*(C`:utf8\*(C'\fR, is stronglyrecommended..IP ":bytes" 4.IX Item ":bytes"This is the inverse of \f(CW\*(C`:utf8\*(C'\fR layer. It turns off the flagon the layer below so that data read from it is considered tobe \*(L"octets\*(R" i.e. characters in range 0..255 only. Likewiseon output perl will warn if a \*(L"wide\*(R" character is writtento a such a stream..IP ":raw" 4.IX Item ":raw"The \f(CW\*(C`:raw\*(C'\fR layer is \fIdefined\fR as being identical to calling\&\f(CW\*(C`binmode($fh)\*(C'\fR \- the stream is made suitable for passing binary datai.e. each byte is passed as-is. The stream will still bebuffered..SpIn Perl 5.6 and some books the \f(CW\*(C`:raw\*(C'\fR layer (previously sometimes alsoreferred to as a \*(L"discipline\*(R") is documented as the inverse of the\&\f(CW\*(C`:crlf\*(C'\fR layer. That is no longer the case \- other layers which wouldalter binary nature of the stream are also disabled.  If you want \s-1UNIX\s0line endings on a platform that normally does \s-1CRLF\s0 translation, but stillwant \s-1UTF\-8\s0 or encoding defaults the appropriate thing to do is to add\&\f(CW\*(C`:perlio\*(C'\fR to \s-1PERLIO\s0 environment variable..SpThe implementation of \f(CW\*(C`:raw\*(C'\fR is as a pseudo-layer which when \*(L"pushed\*(R"pops itself and then any layers which do not declare themselves as suitablefor binary data. (Undoing :utf8 and :crlf are implemented by clearingflags rather than popping layers but that is an implementation detail.).SpAs a consequence of the fact that \f(CW\*(C`:raw\*(C'\fR normally pops layersit usually only makes sense to have it as the only or first element ina layer specification.  When used as the first element it providesa known base on which to build e.g..Sp.Vb 1\&    open($fh,":raw:utf8",...).Ve.Spwill construct a \*(L"binary\*(R" stream, but then enable \s-1UTF\-8\s0 translation..IP ":pop" 4.IX Item ":pop"A pseudo layer that removes the top-most layer. Gives perl codea way to manipulate the layer stack. Should be consideredas experimental. Note that \f(CW\*(C`:pop\*(C'\fR only works on real layersand will not undo the effects of pseudo layers like \f(CW\*(C`:utf8\*(C'\fR.An example of a possible use might be:.Sp.Vb 5\&    open($fh,...)\&    ...\&    binmode($fh,":encoding(...)");  # next chunk is encoded\&    ...\&    binmode($fh,":pop");            # back to un\-encoded.Ve.SpA more elegant (and safer) interface is needed..IP ":win32" 4.IX Item ":win32"On Win32 platforms this \fIexperimental\fR layer uses native \*(L"handle\*(R" \s-1IO\s0rather than unix-like numeric file descriptor layer. Known to bebuggy as of perl 5.8.2..Sh "Custom Layers".IX Subsection "Custom Layers"It is possible to write custom layers in addition to the above builtinones, both in C/XS and Perl.  Two such layers (and one example writtenin Perl using the latter) come with the Perl distribution..IP ":encoding" 4.IX Item ":encoding"Use \f(CW\*(C`:encoding(ENCODING)\*(C'\fR either in \fIopen()\fR or \fIbinmode()\fR to installa layer that does transparently character set and encoding transformations,for example from Shift-JIS to Unicode.  Note that under \f(CW\*(C`stdio\*(C'\fRan \f(CW\*(C`:encoding\*(C'\fR also enables \f(CW\*(C`:utf8\*(C'\fR.  See PerlIO::encodingfor more information..IP ":via" 4.IX Item ":via"Use \f(CW\*(C`:via(MODULE)\*(C'\fR either in \fIopen()\fR or \fIbinmode()\fR to install a layerthat does whatever transformation (for example compression /decompression, encryption / decryption) to the filehandle.See PerlIO::via for more information..Sh "Alternatives to raw".IX Subsection "Alternatives to raw"To get a binary stream an alternate method is to use:.PP.Vb 2\&    open($fh,"whatever")\&    binmode($fh);.Ve.PPthis has advantage of being backward compatible with how such things havehad to be coded on some platforms for years..PPTo get an un-buffered stream specify an unbuffered layer (e.g. \f(CW\*(C`:unix\*(C'\fR)in the open call:.PP.Vb 1\&    open($fh,"<:unix",$path).Ve.Sh "Defaults and how to override them".IX Subsection "Defaults and how to override them"If the platform is MS-DOS like and normally does \s-1CRLF\s0 to \*(L"\en\*(R"translation for text files then the default layers are :.PP.Vb 1\&  unix crlf.Ve.PP(The low level \*(L"unix\*(R" layer may be replaced by a platform specific lowlevel layer.).PPOtherwise if \f(CW\*(C`Configure\*(C'\fR found out how to do \*(L"fast\*(R" \s-1IO\s0 using system'sstdio, then the default layers are:.PP.Vb 1\&  unix stdio.Ve.PPOtherwise the default layers are.PP.Vb 1\&  unix perlio.Ve.PPThese defaults may change once perlio has been better tested and tuned..PPThe default can be overridden by setting the environment variable\&\s-1PERLIO\s0 to a space separated list of layers (\f(CW\*(C`unix\*(C'\fR or platform lowlevel layer is always pushed first)..PPThis can be used to see the effect of/bugs in the various layers e.g..PP.Vb 3\&  cd .../perl/t\&  PERLIO=stdio  ./perl harness\&  PERLIO=perlio ./perl harness.Ve.PPFor the various value of \s-1PERLIO\s0 see \*(L"\s-1PERLIO\s0\*(R" in perlrun..Sh "Querying the layers of filehandles".IX Subsection "Querying the layers of filehandles"The following returns the \fBnames\fR of the PerlIO layers on a filehandle..PP.Vb 1\&   my @layers = PerlIO::get_layers($fh); # Or FH, *FH, "FH"..Ve.PPThe layers are returned in the order an \fIopen()\fR or \fIbinmode()\fR call woulduse them.  Note that the \*(L"default stack\*(R" depends on the operatingsystem and on the Perl version, and both the compile-time andruntime configurations of Perl..PPThe following table summarizes the default layers on UNIX-like andDOS-like platforms and depending on the setting of the \f(CW$ENV{PERLIO}\fR:.PP.Vb 6\& PERLIO     UNIX\-like                   DOS\-like\& \-\-\-\-\-\-     \-\-\-\-\-\-\-\-\-                   \-\-\-\-\-\-\-\-\& unset / "" unix perlio / stdio [1]     unix crlf\& stdio      unix perlio / stdio [1]     stdio\& perlio     unix perlio                 unix perlio\& mmap       unix mmap                   unix mmap\&\& # [1] "stdio" if Configure found out how to do "fast stdio" (depends\& # on the stdio implementation) and in Perl 5.8, otherwise "unix perlio".Ve.PPBy default the layers from the input side of the filehandle isreturned, to get the output side use the optional \f(CW\*(C`output\*(C'\fR argument:.PP.Vb 1\&   my @layers = PerlIO::get_layers($fh, output => 1);.Ve.PP(Usually the layers are identical on either side of a filehandle butfor example with sockets there may be differences, or if you havebeen using the \f(CW\*(C`open\*(C'\fR pragma.).PPThere is no \fIset_layers()\fR, nor does \fIget_layers()\fR return a tied arraymirroring the stack, or anything fancy like that.  This is notaccidental or unintentional.  The PerlIO layer stack is a bit morecomplicated than just a stack (see for example the behaviour of \f(CW\*(C`:raw\*(C'\fR).You are supposed to use \fIopen()\fR and \fIbinmode()\fR to manipulate the stack..PP\&\fBImplementation details follow, please close your eyes.\fR.PPThe arguments to layers are by default returned in parenthesis afterthe name of the layer, and certain layers (like \f(CW\*(C`utf8\*(C'\fR) are not reallayers but instead flags on real layers: to get all of these returnedseparately use the optional \f(CW\*(C`details\*(C'\fR argument:.PP.Vb 1\&   my @layer_and_args_and_flags = PerlIO::get_layers($fh, details => 1);.Ve.PPThe result will be up to be three times the number of layers:the first element will be a name, the second element the arguments(unspecified arguments will be \f(CW\*(C`undef\*(C'\fR), the third element the flags,the fourth element a name again, and so forth..PP\&\fBYou may open your eyes now.\fR.SH "AUTHOR".IX Header "AUTHOR"Nick Ing-Simmons <nick@ing\-simmons.net>.SH "SEE ALSO".IX Header "SEE ALSO"\&\*(L"binmode\*(R" in perlfunc, \*(L"open\*(R" in perlfunc, perlunicode, perliol,Encode

⌨️ 快捷键说明

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