Perl闭包实例解释

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

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. NGINX 1.31.7: Native GeoIP2 support, HTTP/2 priorities, and QUIC improvements (2026-11-13 23:40:02)
  2. 说说广场 API 0.31.0 版的调用代码说明 (2026-11-13 19:10:02)
  3. NGINX Routing on HTTP Request Body (2026-10-27 14:10:42)

查看更多 后端 文章 →

建议继续学习

  1. 如何成为Python高手 (累计阅读 55,545)
  2. perl更新/修改/删除文本文件内容 (累计阅读 10,901)
  3. perl大牛flw传说 (累计阅读 8,015)
  4. AWStats是一个基于Perl的WEB日志分析工具。 (累计阅读 7,595)
  5. perl模块Getopt::Std用法及实例-从命令行读取参数模块 (累计阅读 7,357)
  6. 为什么Lisp语言如此先进?(译文) (累计阅读 6,772)
  7. [Perl] Template::Toolkit 模板技术. (累计阅读 6,674)
  8. PHP将死,何以为继? (累计阅读 6,219)
  9. Perl命令行常见用法及技巧 (累计阅读 6,155)
  10. 通过使用Chrome的开发者工具来学习JavaScript (累计阅读 6,138)