Posted By

johngh on 11/24/09


Tagged

closure perl


Versions (?)

Closure


 / Published in: Perl
 

  1. #!/usr/bin/perl -w
  2. #
  3. #
  4. #
  5. use strict;
  6.  
  7. my $x = 12;
  8. { my $x; sub inc { $x++; print "$x\n" } sub dec { $x-- ; print "$x\n"} }
  9.  
  10. inc();
  11. inc();
  12. inc();
  13. inc();
  14. dec();
  15. inc();
  16.  
  17. print "$x\n";

Report this snippet  

You need to login to post a comment.