01: #! /usr/bin/perl 02: use warnings; 03: use strict; 04: 05: # ============================================================ 06: { # Beginn der Closure 07: my $counter = 0; 08: # ------------------------------------------------------------ 09: sub ZaehleHoch { 10: $counter++; 11: } # ZaehleHoch 12: # ------------------------------------------------------------ 13: sub ZaehleRunter { 14: $counter--; 15: } # ZaehleRunter 16: # ------------------------------------------------------------ 17: sub GibMirDenCounterWert { 18: return $counter; 19: } # GibMirDenCounterWert 20: # ------------------------------------------------------------ 21: 22: } # Ende der Closure 23: # ============================================================ 24: 25: print &GibMirDenCounterWert(), "\n"; 26: for my $i (1..20) { 27: &ZaehleHoch(); 28: } # for 29: print &GibMirDenCounterWert(), "\n"; 30: for my $i (4..9) { 31: &ZaehleRunter(); 32: } # for 33: print &GibMirDenCounterWert(), "\n";