/[<">
Heim Datenbank MySQL-Tutorial perl程序设计技巧

perl程序设计技巧

Jun 07, 2016 pm 03:23 PM
pass perl poe 技巧 程序设计

1. Why does POE pass parameters as array slices? http://poe.perl.org/?POE_FAQ/calling_convention 2. perl regular expression fast referecnces metacharacters are {}[]() ^ $ . | * + ? a metacharacter can be matched by putting a backslash befo

1. Why does POE pass parameters as array slices?
http://poe.perl.org/?POE_FAQ/calling_convention

2.  perl regular expression fast referecnces
metacharacters are

perl程序设计技巧{ } [ ] ( ) ^ $ . |  * + ? 

a metacharacter can be matched by putting a backslash before it
anchor metacharacters ^ and $ .
The anchor ^ means match at the beginning of the string and the anchor $ means match at the end of the string, or before a newline at the end of the string.

perl程序设计技巧"housekeeper" =~ /keeper/;          # matches
perl程序设计技巧
"housekeeper" =~ /^keeper/;        # doesn't match
perl程序设计技巧
"housekeeper" =~ /keeper$/;        # matches
perl程序设计技巧
"housekeeper " =~ /keeper$/;    # matchesperl程序设计技巧

A character class allows a set of possible characters, rather than just a single character, to match at a particular point in a regexp.Character classes are denoted by brackets [...], with the set of characters to be possiblly matched inside. Some examples:

perl程序设计技巧/cat/;      #matches 'cat'
perl程序设计技巧
/[bcr]at/;  #matches 'bat', 'cat', or 'rat'
perl程序设计技巧
/item[0123456789]/;   #matches 'item0' or ... or 'item9'
perl程序设计技巧
"abc" =~ /[cab]/;  #matches 'a'
perl程序设计技巧
/[yY][eE][sS]/ can be rewritten as /yes/i.

The 'i' stands for case-insensitive and is an example of a modifier of the matching operation.
The special characters for a character class are - ] / ^ $ (and the pattern delimiter, whatever it is). ] is special because it denotes the end of a character class. $ is special because it denotes a scalar variable. / is special because it is used in escape sequences.

perl程序设计技巧/[/]c]def/# matches ']def' or 'cdef'
perl程序设计技巧
   $x = 'bcr';
perl程序设计技巧   
/[$x]at/;   # matches 'bat', 'cat', or 'rat'
perl程序设计技巧
   /[/$x]at/;  # matches '$at' or 'xat'
perl程序设计技巧
   /[//$x]at/# matches '/at', 'bat, 'cat', or 'rat'

The specia character '-' acts as a range operator within a character class.

perl程序设计技巧/item[0-9]/;  # matches 'item0' or ... or 'item9'
perl程序设计技巧
/[0-9bx-z]aa/;  # matches '0aa', ..., '9aa',
perl程序设计技巧                    # 'baa', 'xaa', 'yaa', or 'zaa'

   /[0-9a-fA-F]/;  # matches a hexadecimal digit
   /[0-9a-zA-Z_]/# matches a "word" character,
perl程序设计技巧                    # like those in a Perl variable name

If '-' is the first or last character in a character class, it is treated as an ordinary character; [-ab], [ab-] and [a/-b] are all equivalent.
The special character ^ in the first position of a character class denotes a negated character class, which matches any characters but those in the brackets.

perl程序设计技巧    /[^a]at/;  # doesn't match 'aat' or 'at', but matches
perl程序设计技巧               # all other 'bat', 'cat, '0at', '%at', etc.

perl程序设计技巧
    /[^0-9]/;  # matches a non-numeric character
perl程序设计技巧
    /[a^]at/;  # matches 'aat' or '^at'; here '^' is ordinary

perl程序设计技巧/d matches a digit, not just [0-9] but also digits from non-roman scripts
perl程序设计技巧/
s matches a whitespace character, the set [/ /t/r/n/f] and others
perl程序设计技巧/
w matches a word character (alphanumeric or _), not just [0-9a-zA-Z_] but also digits and 
perl程序设计技巧     characters from non
-roman scripts
perl程序设计技巧/
D is a negated /d; it represents any other character than a digit, or [^/d]
perl程序设计技巧/
S is a negated /s; it represents any non-whitespace character [^/s]
perl程序设计技巧/
W is a negated /w; it represents any non-word character [^/w]
perl程序设计技巧The period 
'.' matches any character but "/n" (unless the modifier //s is in effect, as explained
perl程序设计技巧below)
.

perl程序设计技巧    //d/d:/d/d:/d/d/# matches a hh:mm:ss time format
perl程序设计技巧
    /[/d/s]/;         # matches any digit or whitespace character
perl程序设计技巧
    //w/W/w/;         # matches a word char, followed by a
perl程序设计技巧                      # non-word char, followed by a word char

perl程序设计技巧
    /..rt/;           # matches any two chars, followed by 'rt'
perl程序设计技巧
    /end/./;          # matches 'end.'
perl程序设计技巧
    /end[.]/;         # same thing, matches 'end.'

The alternation metacharacter | .To match dog or cat, we  form the
regexp dog|cat. As before, Perl will try to match the  regexp at the earliest possible point in the
string. At each  character position, Perl will first try to match the first  alternative, dog. If dog doesn't
match, Perl will then try the  next alternative, cat. If cat doesn't match either, then the  match fails and
Perl moves to the next position in the string.

perl程序设计技巧    "cats and dogs" =~ /cat|dog|bird/;  # matches "cat"
perl程序设计技巧
    "cats and dogs" =~ /dog|cat|bird/;  # matches "cat"

() is grouping metacharacter.

perl程序设计技巧    /(a|b)b/;    # matches 'ab' or 'bb'
perl程序设计技巧
    /(ac|b)b/;   # matches 'acb' or 'bb'
perl程序设计技巧
    /(^a|b)c/;   # matches 'ac' at start of string or 'bc' anywhere
perl程序设计技巧
    /(a|[bc])d/# matches 'ad', 'bd', or 'cd'
perl程序设计技巧
    /house(cat|)/;  # matches either 'housecat' or 'house'
perl程序设计技巧
    /house(cat(s|)|)/;  # matches either 'housecats' or 'housecat' or
perl程序设计技巧                        # 'house'.  Note groups can be nested.

perl程序设计技巧
    /(19|20|)/d/d/;  # match years 19xx, 20xx, or the Y2K problem, xx
perl程序设计技巧
    "20" =~ /(19|20|)/d/d/;  # matches the null alternative '()dd',
perl程序设计技巧                             # because '20dd' can't match

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Artikel -Tags

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Teilen von Win11-Tipps: Ein Trick, um die Anmeldung mit einem Microsoft-Konto zu überspringen Teilen von Win11-Tipps: Ein Trick, um die Anmeldung mit einem Microsoft-Konto zu überspringen Mar 27, 2024 pm 02:57 PM

Teilen von Win11-Tipps: Ein Trick, um die Anmeldung mit einem Microsoft-Konto zu überspringen

Was sind die Tipps für Anfänger zum Erstellen von Formularen? Was sind die Tipps für Anfänger zum Erstellen von Formularen? Mar 21, 2024 am 09:11 AM

Was sind die Tipps für Anfänger zum Erstellen von Formularen?

VSCode-Erste-Schritte-Leitfaden: Ein Muss für Anfänger, um die Verwendungsfähigkeiten schnell zu erlernen! VSCode-Erste-Schritte-Leitfaden: Ein Muss für Anfänger, um die Verwendungsfähigkeiten schnell zu erlernen! Mar 26, 2024 am 08:21 AM

VSCode-Erste-Schritte-Leitfaden: Ein Muss für Anfänger, um die Verwendungsfähigkeiten schnell zu erlernen!

Ein Muss für Veteranen: Tipps und Vorsichtsmaßnahmen für * und & in C-Sprache Ein Muss für Veteranen: Tipps und Vorsichtsmaßnahmen für * und & in C-Sprache Apr 04, 2024 am 08:21 AM

Ein Muss für Veteranen: Tipps und Vorsichtsmaßnahmen für * und & in C-Sprache

PHP-Programmierkenntnisse: So springen Sie innerhalb von 3 Sekunden zur Webseite PHP-Programmierkenntnisse: So springen Sie innerhalb von 3 Sekunden zur Webseite Mar 24, 2024 am 09:18 AM

PHP-Programmierkenntnisse: So springen Sie innerhalb von 3 Sekunden zur Webseite

Enthüllte Win11-Tricks: So umgehen Sie die Anmeldung bei einem Microsoft-Konto Enthüllte Win11-Tricks: So umgehen Sie die Anmeldung bei einem Microsoft-Konto Mar 27, 2024 pm 07:57 PM

Enthüllte Win11-Tricks: So umgehen Sie die Anmeldung bei einem Microsoft-Konto

Die neuen Funktionen von Poe sind so leistungsstark! Selbst ohne Programmierkenntnisse können Sie in 10 Minuten einen Meme-Editor erstellen Die neuen Funktionen von Poe sind so leistungsstark! Selbst ohne Programmierkenntnisse können Sie in 10 Minuten einen Meme-Editor erstellen Aug 02, 2024 am 12:23 AM

Die neuen Funktionen von Poe sind so leistungsstark! Selbst ohne Programmierkenntnisse können Sie in 10 Minuten einen Meme-Editor erstellen

Düstere Schlägerei diese Woche: POE startet in eine neue Saison! Diablo-Handyspiel führt automatische Auflegefunktion ein Düstere Schlägerei diese Woche: POE startet in eine neue Saison! Diablo-Handyspiel führt automatische Auflegefunktion ein Mar 25, 2024 pm 06:31 PM

Düstere Schlägerei diese Woche: POE startet in eine neue Saison! Diablo-Handyspiel führt automatische Auflegefunktion ein

See all articles