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

📄 perlfaq6.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 4 页
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "PERLFAQ6 1".TH PERLFAQ6 1 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"perlfaq6 \- Regular Expressions ($Revision: 10126 $).SH "DESCRIPTION".IX Header "DESCRIPTION"This section is surprisingly small because the rest of the \s-1FAQ\s0 islittered with answers involving regular expressions.  For example,decoding a \s-1URL\s0 and checking whether something is a number are handledwith regular expressions, but those answers are found elsewhere inthis document (in perlfaq9: \*(L"How do I decode or create those %\-encodingson the web\*(R" and perlfaq4: \*(L"How do I determine whether a scalar isa number/whole/integer/float\*(R", to be precise)..Sh "How can I hope to use regular expressions without creating illegible and unmaintainable code?".IX Xref "regex, legibility regexp, legibility regular expression, legibility  x".IX Subsection "How can I hope to use regular expressions without creating illegible and unmaintainable code?"Three techniques can make regular expressions maintainable andunderstandable..IP "Comments Outside the Regex" 4.IX Item "Comments Outside the Regex"Describe what you're doing and how you're doing it, using normal Perlcomments..Sp.Vb 3\&        # turn the line into the first word, a colon, and the\&        # number of characters on the rest of the line\&        s/^(\ew+)(.*)/ lc($1) . ":" . length($2) /meg;.Ve.IP "Comments Inside the Regex" 4.IX Item "Comments Inside the Regex"The \f(CW\*(C`/x\*(C'\fR modifier causes whitespace to be ignored in a regex pattern(except in a character class), and also allows you to use normalcomments there, too.  As you can imagine, whitespace and comments helpa lot..Sp\&\f(CW\*(C`/x\*(C'\fR lets you turn this:.Sp.Vb 1\&        s{<(?:[^>\*(Aq"]*|".*?"|\*(Aq.*?\*(Aq)+>}{}gs;.Ve.Spinto this:.Sp.Vb 10\&        s{ <                    # opening angle bracket\&                (?:                 # Non\-backreffing grouping paren\&                        [^>\*(Aq"] *        # 0 or more things that are neither > nor \*(Aq nor "\&                                |           #    or else\&                        ".*?"           # a section between double quotes (stingy match)\&                                |           #    or else\&                        \*(Aq.*?\*(Aq           # a section between single quotes (stingy match)\&                ) +                 #   all occurring one or more times\&                >                   # closing angle bracket\&        }{}gsx;                 # replace with nothing, i.e. delete.Ve.SpIt's still not quite so clear as prose, but it is very useful fordescribing the meaning of each part of the pattern..IP "Different Delimiters" 4.IX Item "Different Delimiters"While we normally think of patterns as being delimited with \f(CW\*(C`/\*(C'\fRcharacters, they can be delimited by almost any character.  perlredescribes this.  For example, the \f(CW\*(C`s///\*(C'\fR above uses braces asdelimiters.  Selecting another delimiter can avoid quoting thedelimiter within the pattern:.Sp.Vb 2\&        s/\e/usr\e/local/\e/usr\e/share/g;  # bad delimiter choice\&        s#/usr/local#/usr/share#g;              # better.Ve.Sh "I'm having trouble matching over more than one line.  What's wrong?".IX Xref "regex, multiline regexp, multiline regular expression, multiline".IX Subsection "I'm having trouble matching over more than one line.  What's wrong?"Either you don't have more than one line in the string you're lookingat (probably), or else you aren't using the correct modifier(s) onyour pattern (possibly)..PPThere are many ways to get multiline data into a string.  If you wantit to happen automatically while reading input, you'll want to set $/(probably to '' for paragraphs or \f(CW\*(C`undef\*(C'\fR for the whole file) toallow you to read more than one line at a time..PPRead perlre to help you decide which of \f(CW\*(C`/s\*(C'\fR and \f(CW\*(C`/m\*(C'\fR (or both)you might want to use: \f(CW\*(C`/s\*(C'\fR allows dot to include newline, and \f(CW\*(C`/m\*(C'\fRallows caret and dollar to match next to a newline, not just at theend of the string.  You do need to make sure that you've actuallygot a multiline string in there..PPFor example, this program detects duplicate words, even when they spanline breaks (but not paragraph ones).  For this example, we don't need\&\f(CW\*(C`/s\*(C'\fR because we aren't using dot in a regular expression that we wantto cross line boundaries.  Neither do we need \f(CW\*(C`/m\*(C'\fR because we aren'twanting caret or dollar to match at any point inside the record nextto newlines.  But it's imperative that $/ be set to something otherthan the default, or else we won't actually ever have a multilinerecord read in..PP.Vb 6\&        $/ = \*(Aq\*(Aq;                # read in more whole paragraph, not just one line\&        while ( <> ) {\&                while ( /\eb([\ew\*(Aq\-]+)(\es+\e1)+\eb/gi ) {   # word starts alpha\&                        print "Duplicate $1 at paragraph $.\en";\&                }\&        }.Ve.PPHere's code that finds sentences that begin with \*(L"From \*(R" (which wouldbe mangled by many mailers):.PP.Vb 6\&        $/ = \*(Aq\*(Aq;                # read in more whole paragraph, not just one line\&        while ( <> ) {\&                while ( /^From /gm ) { # /m makes ^ match next to \en\&                print "leading from in paragraph $.\en";\&                }\&        }.Ve.PPHere's code that finds everything between \s-1START\s0 and \s-1END\s0 in a paragraph:.PP.Vb 6\&        undef $/;               # read in whole file, not just one line or paragraph\&        while ( <> ) {\&                while ( /START(.*?)END/sgm ) { # /s makes . cross line boundaries\&                    print "$1\en";\&                }\&        }.Ve.Sh "How can I pull out lines between two patterns that are themselves on different lines?".IX Xref "..".IX Subsection "How can I pull out lines between two patterns that are themselves on different lines?"You can use Perl's somewhat exotic \f(CW\*(C`..\*(C'\fR operator (documented inperlop):.PP.Vb 1\&        perl \-ne \*(Aqprint if /START/ .. /END/\*(Aq file1 file2 ....Ve.PPIf you wanted text and not lines, you would use.PP.Vb 1\&        perl \-0777 \-ne \*(Aqprint "$1\en" while /START(.*?)END/gs\*(Aq file1 file2 ....Ve.PPBut if you want nested occurrences of \f(CW\*(C`START\*(C'\fR through \f(CW\*(C`END\*(C'\fR, you'llrun up against the problem described in the question in this sectionon matching balanced text..PPHere's another example of using \f(CW\*(C`..\*(C'\fR:.PP.Vb 7\&        while (<>) {\&                $in_header =   1  .. /^$/;\&                $in_body   = /^$/ .. eof;\&        # now choose between them\&        } continue {\&                $. = 0 if eof;  # fix $.\&        }.Ve.Sh "I put a regular expression into $/ but it didn't work. What's wrong?".IX Xref "$ , regexes in $INPUT_RECORD_SEPARATOR, regexes in $RS, regexes in".IX Subsection "I put a regular expression into $/ but it didn't work. What's wrong?"$/ has to be a string.  You can use these examples if you really need to do this..PPIf you have File::Stream, this is easy..PP.Vb 1\&        use File::Stream;

⌨️ 快捷键说明

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