Help for this page

Select Code to Download


  1. or download this
    sub create_closure {
       my ($obj) = @_;
    ...
       my $sub = create_closure($existing_obj);
    }
    &$sub();  # Prints 1234, even though $existing_obj is out of scope.
    
  2. or download this
    our $global_obj;
    
    ...
    my $sub = sub { print($global_obj, $/); };
    $global_obj = 5678;
    &$sub();  # Prints 5678.