prints#!/usr/bin/perl -w use strict; doStuff(); sub doStuff { my $toggle = initToggle( 1 ); for ( 1..6 ) { print &$toggle . "\n" }; print "now something different...\n"; &othersub($toggle); } sub initToggle { my $x = shift; return sub { $x ^= 1; return $x }; } sub othersub { my $c = shift; print ref($c) ."\n"; for ( 1..6 ) { print &$c . "\n" }; }
as expected... (perl 5.005_03 i386-linux)0 1 0 1 0 1 now something different... CODE 0 1 0 1 0 1
In reply to Re: Closures question
by cianoz
in thread Closures question
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |