On Fri, 5 Oct 2001, Bill Jones wrote:

> Not in this *example test* world I created for students (at least I didn't
> want them too.)  Recently I started teaching Perl as an Internet Programming
> class (CGS2557) here at FCCJ and one of my students asked if it was possible
> to get at it somehow - I said I didn't think so, but to be sure I wanted to
> ask here.

What you can do, though, is show them cool little tricks you can do with
scoping, such as closures.  Here, you create a code reference that uses
variables that are out of scope, but still exist within the scope of the
anonymous subroutine.  Consider:

sub gen_sub {

        my $text = "This is within the scope of gen_sub";
        return sub { print "$text\n" }
}

my $new_sub = gen_sub();

$new_sub->();

This prints out the contents of $text, even though $text is lexically
scoped to gen_sub.  Cool, huh?

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
meterologist, n.:
        One who doubts the established fact that it is
        bound to rain if you forget your umbrella.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to