/[<">
首页数据库mysql教程perl程序设计技巧
perl程序设计技巧Jun 07, 2016 pm 03:23 PM
passperlpoe技巧程序设计

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

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
提高 Python 代码可读性的五个基本技巧提高 Python 代码可读性的五个基本技巧Apr 12, 2023 pm 08:58 PM

Python 中有许多方法可以帮助我们理解代码的内部工作原理,良好的编程习惯,可以使我们的工作事半功倍!例如,我们最终可能会得到看起来很像下图中的代码。虽然不是最糟糕的,但是,我们需要扩展一些事情,例如:load_las_file 函数中的 f 和 d 代表什么?为什么我们要在 clay 函数中检查结果?这些函数需要什么类型?Floats? DataFrames?在本文中,我们将着重讨论如何通过文档、提示输入和正确的变量名称来提高应用程序/脚本的可读性的五个基本技巧。1. Comments我们可

提高Python代码可读性的五个基本技巧提高Python代码可读性的五个基本技巧Apr 11, 2023 pm 09:07 PM

译者 | 赵青窕审校 | 孙淑娟你是否经常回头看看6个月前写的代码,想知道这段代码底是怎么回事?或者从别人手上接手项目,并且不知道从哪里开始?这样的情况对开发者来说是比较常见的。Python中有许多方法可以帮助我们理解代码的内部工作方式,因此当您从头来看代码或者写代码时,应该会更容易地从停止的地方继续下去。在此我给大家举个例子,我们可能会得到如下图所示的代码。这还不是最糟糕的,但有一些事情需要我们去确认,例如:在load_las_file函数中f和d代表什么?为什么我们要在clay函数中检查结果

使用Vue.js和Perl语言开发高效的网络爬虫和数据抓取工具使用Vue.js和Perl语言开发高效的网络爬虫和数据抓取工具Jul 31, 2023 pm 06:43 PM

使用Vue.js和Perl语言开发高效的网络爬虫和数据抓取工具近年来,随着互联网的迅猛发展和数据的日益重要,网络爬虫和数据抓取工具的需求也越来越大。在这个背景下,结合Vue.js和Perl语言开发高效的网络爬虫和数据抓取工具是一种不错的选择。本文将介绍如何使用Vue.js和Perl语言开发这样一个工具,并附上相应的代码示例。一、Vue.js和Perl语言的介

使用Python和Perl构建高性能Web应用程序的最佳实践使用Python和Perl构建高性能Web应用程序的最佳实践Jun 17, 2023 am 08:09 AM

在当今数字时代,Web应用程序越来越普遍,让我们的生活更加便利和高效。Python和Perl是两种广泛使用的编程语言,它们都是构建Web应用程序的理想选择。但是,要想建立高性能的Web应用程序,需要掌握一些最佳实践,本文将介绍一些Python和Perl构建高性能Web应用程序的最佳实践。选择合适的Web框架选择一个合适的Web框架是一个设计高性能Web应用程

Python中简单易用的并行加速技巧Python中简单易用的并行加速技巧Apr 12, 2023 pm 02:25 PM

1.简介我们在日常使用Python进行各种数据计算处理任务时,若想要获得明显的计算加速效果,最简单明了的方式就是想办法将默认运行在单个进程上的任务,扩展到使用多进程或多线程的方式执行。而对于我们这些从事数据分析工作的人员而言,以最简单的方式实现等价的加速运算的效果尤为重要,从而避免将时间过多花费在编写程序上。而今天的文章费老师我就来带大家学习如何利用joblib这个非常简单易用的库中的相关功能,来快速实现并行计算加速效果。2.使用joblib进行并行计算作为一个被广泛使用的第三方Python库(

使用Vue.js和Perl语言开发系统脚本和自动化工具使用Vue.js和Perl语言开发系统脚本和自动化工具Jul 29, 2023 pm 04:57 PM

使用Vue.js和Perl语言开发系统脚本和自动化工具在当前的软件开发环境中,系统脚本和自动化工具已经成为开发人员节省时间和提高效率的重要工具。在这篇文章中,我们将介绍如何使用Vue.js和Perl语言开发系统脚本和自动化工具,并提供一些代码示例。Vue.js是一个流行的JavaScript框架,用于构建用户界面。它采用组件化的开发方式,使得开发人员可以将代

四种Python推导式开发技巧,让你的代码更高效四种Python推导式开发技巧,让你的代码更高效Apr 22, 2023 am 09:40 AM

对于数据科学,Python通常被广泛地用于进行数据的处理和转换,它提供了强大的数据结构处理的函数,使数据处理更加灵活,这里说的“灵活性”是什么意思?这意味着在Python中总是有多种方法来实现相同的结果,我们总是有不同的方法并且需要从中选择易于使用、省时并能更好控制的方法。要掌握所有的这些方法是不可能的。所以这里列出了在处理任何类型的数据时应该知道的4个Python技巧。列表推导式ListComprehension是创建列表的一种优雅且最符合python语言的方法。与for循环和if语句相比,列

Linux下如何用Nginx作Perl程序服务器及其中Perl模块Linux下如何用Nginx作Perl程序服务器及其中Perl模块May 16, 2023 pm 11:25 PM

perl+fastcgi+nginx搭建nginx+fastcgi是php下最流行的一套环境了,那perl会不会也有fastcgi呢,当然有,今天来搭建下nginx下perl的fastcgi.性能方面也不亚于php,但是现在web程序php的流行程度perl无法比拟了,性能再好也枉然,但是部分小功能可以考虑使用perl的fastcgi来搞定.进入正题.1.准备软件环境:nginxperl:系统自带fastcgi1.2perl安装一般linux都有自带perl,可以不用安装,如果确实没有,请执行:

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器