eval的两个作用
2012-06-15 09:52
134 查看
1 捕获错误
2 动态代码
# Catch exception with eval # This is an exception of divided by zero # if errors happened, perl stores it in $@ # you should check $@ immediately after eval {} block # Note, eval is a function, not a flow control clause # you need to add ';' after the block use strict; use warnings; eval { return 2 / 0; }; print $@ if $@;
2 动态代码
# Dynamic code with eval # syntax: eval "code" # The script will execute the code after eval in run time use strict; use warnings; sub test { my $num1 = 2; my $num2 = 3; foreach my $op (qw!+ - * /!) { print "$num1 $op $num2 equals "; print eval "$num1 $op $num2", "\n"; } } test()
相关文章推荐
- 找出数组中两个只出现一次的数字;异或运算^的一个作用
- BETWEEN 操作符在 WHERE 子句中使用,作用是选取介于两个值之间的数据范围。
- BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用
- eval的作用
- typename的两个作用
- spring 配置文件中的ref元素的作用是什么?它的两个基本属性是什么?
- 酷乐视S3主板M_DIR和M_P两个信号的作用
- perl-- eval的作用
- 为什么会有OutputStreamWriter和InputStreamReader两个转换类的出现以及它们的作用
- C#中两个冒号(::)的作用
- 创建进程时,CreateProcess的前两个参数的作用
- 单片机晶振上两个电容的作用
- JavaScript中两个感叹号(!!)的作用
- JavaScript中两个感叹号的作用
- synchronized的两个作用
- JavaScript中两个感叹号的作用说明
- 单片机晶振上两个电容的作用
- static函数主要有两个作用:
- 两个感叹号作用