DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Closure

12.09.2009
| 1695 views |
  • submit to reddit
        
#!/usr/bin/perl -w
#
#
#
use strict;

my $x = 12;
{ my $x; sub inc { $x++; print "$x\n" } sub dec { $x-- ; print "$x\n"} }

inc();
inc();
inc();
inc();
dec();
inc();

print "$x\n";