+ -
当前位置:首页 → 问答吧 → perldoc中的兩個小問題

perldoc中的兩個小問題

时间:2010-08-14

来源:互联网

本帖最后由 ztkx 于 2010-08-15 13:44 编辑

沒看懂relative backreference
  1. $a99a = '([a-z])(\d)\g{-1}\g{-2}';

  2.   $line = "code=e99e";
  3. if ($line =~ /^(\w+)=$a99a$/){ # unexpected behavior!
  4. print "$1 is valid\n";
  5. } else {
  6. print "bad line: '$line'\n";
  7. }
复制代码
但是運行時並不能匹配$line

另外一個是grep_step的例子
  1. $number = shift;
  2. [b] $regexp[$_] = shift foreach (0..$number-1);[/b]
  3. @compiled = map qr/$_/, @regexp;
  4. while ($line = <>) {
  5. if ($line =~ /$compiled[0]/) {
  6. print $line;
  7. shift @compiled;
  8. last unless @compiled;
  9. }
  10. }
复制代码
沒看懂$regexp[$_]是什麽意思,而且語法也是錯誤的

作者: ztkx   发布时间: 2010-08-14

自己頂一下

作者: ztkx   发布时间: 2010-08-15