Higher order perl

  • View
    2.882

  • Download
    2

Embed Size (px)

DESCRIPTION

Hokkaido.pm #4

Text of Higher order perl

  • 1. 2011 2 19

2. 2011 2 19 3. 2011 2 19 4. 2011 2 19 5. 2011 2 19 6. 2011 2 19 7. 2011 2 19 8. 2011 2 19 9. 2011 2 19 10. 2011 2 19 11. 2011 2 19 12. 2011 2 19 13. 2011 2 19 14. 2011 2 19 15. 2011 2 19 16. 2011 2 19 17. 2011 2 19 18. 2011 2 19 19. 2011 2 19 20. 2011 2 19 21. 2011 2 19 22. 2011 2 19 23. 2011 2 19 24. 2011 2 19 25. 2011 2 19 26. 2011 2 19 27. 2011 2 19 28. 2011 2 19 29. 2011 2 19 30. 2011 2 19 31. 2011 2 19 32. 2011 2 19 33. 2011 2 19 34. use strict;#my $add = sub { $_[0] + $_[1] };#$add->(3, 4);# => 7use strict;sub add { $_[0] + $_[1];}add(2,4);2011 2 19 35. use strict;my $c = 3my $add = sub { $_[0] + $c};$add->(4);# => 72011 2 19 36. use strict;my $c = 3my $proc = sub { $c++ };$proc->();# 3$proc->();# 4$proc->();# 52011 2 19 37. use strict;sub add { $_[0] + $_[1];}my $func = &add;$func->(3, 4);# => 72011 2 19 38. use strict;#sub generate {my ($a, $b) = @_;sub { $a + $b };}generate(3, 4)->();# => 72011 2 19 39. use strict;use feature qw(say);#sub generate {my ($num) = @_;sub { $num++ };}my $fun = generate(2);say $fun->();# => 2say $fun->();# => 3my $fun2 = generate(2);say $fun2->();# => 2say $fun2->();# => 32011 2 19 40. 2011 2 19 41. 2011 2 19 42. use strict;sub each_line { my ($file, $proc) = @_; open my $fh ($line); } close($fh);}each_line(aaa.txt, sub { print $_[0] } );2011 2 19 43. use strict;sub each_line (&@) { my ($proc, $file) = @_; open my $fh, "