perl中$word = $&;是什么意思啊?

cheery_an 2008-09-23 04:29:34
while ($inputline = <STDIN>) {
while ($inputline =~ /\b[A-Z]\S+/g) {
$word = $&;
$word =~ s/[;.,:-]$//; # remove punctuation
for ($count = 1; $count <= @wordlist;
$count++) {
$found = 0;
if ($wordlist[$count-1] eq $word) {
$found = 1;
$wordcount[$count-1] += 1;
last;
}
}
if ($found == 0) {
$oldlength = @wordlist;
$wordlist[$oldlength] = $word;
$wordcount[$oldlength] = 1;
}
}
}
$word = $&;是什么意思?
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengjc49 2009-09-28
  • 打赏
  • 举报
回复
$& The string matched by the last successful pattern match (not
counting any matches hidden within a BLOCK or eval() enclosed
by the current BLOCK). (Mnemonic: like & in some editors.)
This variable is read-only and dynamically scoped to the
current BLOCK.

The use of this variable anywhere in a program imposes a
considerable performance penalty on all regular expression
matches. See the BUGS manpage.
staff 2008-09-26
  • 打赏
  • 举报
回复

$inputline =~ /\b[A-Z]\S+/g)

上面的正则表达式匹配到的内容。
whatsouta 2008-09-24
  • 打赏
  • 举报
回复
man perlvar
Aylazhang 2008-09-23
  • 打赏
  • 举报
回复
参考:http://perldoc.perl.org/perlvar.html
cheery_an 2008-09-23
  • 打赏
  • 举报
回复
在模式匹配后调用重用部分的结果可用变量$n,全部的结果用变量$&。

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧