regex – 在perl中qr //的含义是什么?

我是perl的新手,并试图设计一个我遇到的词法分析器:
my @token_def =
 (
        [Whitespace => qr{\s+},1],[Comment    => qr{#.*\n?$}m,);

甚至在经过多个网站后我都不理解其含义.

解决方法

qr //是适用于模式匹配和相关活动的类似引号的运算符之一.

perldoc开始:

This operator quotes (and possibly compiles) its STRING as a regular expression. STRING is interpolated the same way as PATTERN in m/PATTERN/. If ' is used as the delimiter,no interpolation is done.

modern_perl开始:

The qr// operator creates first-class regexes. Interpolate them into the match operator to use them:

my $hat = qr/hat/;
say 'Found a hat!' if $name =~ /$hat/;

…或将多个正则表达式对象组合成复杂的模式:

my $hat   = qr/hat/;
my $field = qr/field/;

say 'Found a hat in a field!'
if $name =~ /$hat$field/;

like( $name,qr/$hat$field/,'Found a hat in a field!' );

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...