Chinaunix首页 | 论坛 | 博客
  • 博客访问: 851571
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-09-01 10:35:30

q/STRING/
'STRING'
也可以用其他的分隔符。
    $foo = q!I said, "You said, 'She said it.'"!;
    $bar = q('This is it.');
    $baz = '\n'; # a two-character string

qq/STRING/
"STRING"

A double-quoted, interpolated string.

qx/STRING/

`STRING`   backticks

tr/SEARCHLIST/REPLACEMENTLIST/cdsr
y/SEARCHLIST/REPLACEMENTLIST/cdsr

Transliterates all occurrences of the characters found in the search list with the corresponding character in the replacement list. It returns the number of characters replaced or deleted. If no string is specified via the =~ or !~ operator, the $_ string is transliterated.

A character range may be specified with a hyphen, so does the same replacement as .

对于 sed 的爱好者而言,y/// 就是 tr/// 的同义词。这就是为什么你不能调用名为 y 的函数,同样也不能调用名为 q 或 m 的函数。在所有的其他方面,y/// 都等效于 tr///,并且我们不会再提及它。  把这个操作符放进关于模式匹配的章节看起来其实有点不合适,因为它不使用模式。这个操作符逐字符地扫描一个字串, 然后把每个在 SEARCHLIST (不是正则表达式)里出现的字符替换成对应的来自 REPLACEMENTLIST(也不是替换字串)的字符。但是它看上去象 m// 和 s///,你甚至还可以和它一起使用 =~ 和 !~ 绑定操作符,因此我们在这里描述它。(qr// 和 split 都是模式匹配操作符,但是它们不能和绑定操作符一起使用,因此因此在我们本书的别处描述它们。自己找找看。)  转换返回替换或者删除了的字符个数。如果 没有通过 =~ 或者 !~ 操作符声明的字串,那么使用 $_ 字串。SEARCHLIST 和 REPLACEMENTLIST 可以用一个划线定义一个顺序字符的范围:

阅读(457) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~