IT技术博客大学习 共学习 共进步

Perl闭包实例解释

懒人运维 2009-11-10 23:02:35 浏览 3,061 次

Perl闭包实例解释

以下是代码片段:

#!/usr/bin/perl
sub errorMsg{
   my $lvl=shift;
# define the subroutine to run when called.
   return sub{
      my $msg=shift; #define the error type now.
      print "Err Lever $lvl:$msg\n"}; #print later.
}
$severe=errorMsg("Severe");
$fatal=errorMsg("Fatal");
$annoy=errorMsg(Annoying);
 
&$severe("Divide by zero");
&$fatal("Did you forget to use a semi-colon?");
&$annoy("Uninitialized variable in use");

建议继续学习

  1. perl更新/修改/删除文本文件内容 (阅读 10,521)
  2. perl大牛flw传说 (阅读 7,563)
  3. perl模块Getopt::Std用法及实例-从命令行读取参数模块 (阅读 6,924)
  4. [Perl] Template::Toolkit 模板技术. (阅读 6,221)
  5. Perl命令行常见用法及技巧 (阅读 5,823)
  6. 在perl中连接和使用sqlite做数据存储 (阅读 5,701)
  7. Perl 倒行分析文件方法。perl读文本文件,从末尾往前读. (阅读 5,504)
  8. perl的expect使用方法,实现非交互式登录。 (阅读 5,400)
  9. for 循环为何可恨? (阅读 5,383)
  10. perl模块之MIME::Lite发送有附件的邮件 (阅读 5,221)