On 8/16/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > Paul Lalli wrote: > > So define the subroutine in the same scope as the array. Move the > > subroutine into the if-statement as well. > > Huh? > > Please speak Perl. > > Subroutines are global. Unless they're anonymous. And even then, they are. > It's just difficult to get a hold on them. snip
Subroutines are global, but they can be given access to scopes that are not global. Personally I prefer to use anonymous subroutines for my closures. #!/usr/bin/perl use strict; use warnings; { my $i; sub iter { return $i++ } } my $i = 5; print iter(), "\n"; print iter(), "\n"; print iter(), "\n"; print iter(), "\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/