免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8624 | 回复: 4
打印 上一主题 下一主题

关于 =~ s/../../g 转换的问题 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2009-07-28 08:53 |显示全部楼层

回复 #1 bestnet009 的帖子

$cc = "$3$2$1"; 这个会取$3,$2,$1的值,因为他们都是undef,$cc为空,所以你替换后是空的
试下下面的代码,打印一下$1$2$3.
  1. $aa = "<a>asfsafasdfsa<c>";
  2. $ab = "(<a>)(.*)(<c>)";
  3. $cc = "$3$2$1";
  4. [color=Red]print $1;
  5. print $2;
  6. print $3;[/color]
  7. $aa =~ s/$ab/$cc/g;
  8. print "$aa\n";
复制代码

[ 本帖最后由 Perl_Er 于 2009-7-28 09:02 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-07-28 21:09 |显示全部楼层

回复 #5 bestnet009 的帖子

加这些是为了打印的值,debug.

论坛徽章:
0
3 [报告]
发表于 2009-07-29 10:26 |显示全部楼层

回复 #18 linuxty 的帖子

/e是把//内的当作一段代码执行,第一个里面没有操作符,想一下假设$a$b$c放在一起执行会不会有问题,中间没有操作符连接,
第二个就不用说了,用.操作符连接了。第三个的话吧$1$2$3一起当作了一个字符串。

论坛徽章:
0
4 [报告]
发表于 2009-07-29 15:51 |显示全部楼层
就像 $c='$1', $c的值不就是 一个 $ 和一个 1组成的字符串吗?

这是第一次,还有第二次了。
先休息一下吧。晕了想不清楚的

论坛徽章:
0
5 [报告]
发表于 2009-07-29 17:05 |显示全部楼层
With an eval, you should be especially careful to remember what's being looked at when:

   1. eval $x; # CASE 1
   2. eval "$x"; # CASE 2
   3.
   4. eval '$x'; # CASE 3
   5. eval { $x }; # CASE 4
   6.
   7. eval "\$$x++"; # CASE 5
   8. $$x++; # CASE 6

Cases 1 and 2 above behave identically: they run the code contained in the variable $x. (Although case 2 has misleading double quotes making the reader wonder what else might be happening (nothing is).) Cases 3 and 4 likewise behave in the same way: they run the code '$x' , which does nothing but return the value of $x. (Case 4 is preferred for purely visual reasons, but it also has the advantage of compiling at compile-time instead of at run-time.) Case 5 is a place where normally you would like to use double quotes, except that in this particular situation, you can just use symbolic references instead, as in case 6.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP