Chinaunix首页 | 论坛 | 博客
  • 博客访问: 451384
  • 博文数量: 64
  • 博客积分: 3271
  • 博客等级: 中校
  • 技术积分: 727
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 18:42
文章分类

全部博文(64)

文章存档

2013年(1)

2011年(19)

2010年(42)

2009年(2)

分类: Python/Ruby

2011-03-27 22:13:01

perl中=>(胖箭头)与,(逗号)等价。
perl中,自定义函数在调用时如果不影响程序语义,可以省略括号。
  1. get '/' => sub {
  2.         my $db = connect_db();
  3.         my $sql = 'select id, title, text from entries order by id desc';
  4.         my $sth = $db->prepare($sql) or die $db->errstr;
  5.         $sth->execute or die $sth->errstr;       
  6.  };
代码等价于get('/',sub{});
  1. template 'show_entries.tt', {
  2.                 'msg' => get_flash(),
  3.                 'add_entry_url' => uri_for('/add'),
  4.                 'entries' => $sth->fetchall_hashref('id'),
  5.         };
上面代码等价于template('show_entries.tt', {});
阅读(1752) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~