This quiz tests your knowledge of closures in Perl.

New

Long-Term Learning

Learn efficiently and remember over time.

Start Long-Term Learning

Get personalized study reminders at intervals optimized for better retention.
Track your progress on this set by creating a folder
Or add to an existing folder

Add this set to a folder

  • What is deep binding?

    In deep binding, lexical variables mentioned in anonymous subroutines are the same ones that were in scope when the subroutine was created.

    What is shallow binding?

    In shallow binding, lexical variables mentioned in anonymous subroutines are whichever variables with the same names happen to be in scope when the subroutine is called.

    Does Perl use deep binding or shallow binding?

    Perl always uses deep binding of lexical variables (i.e., those created with my()). However, dynamic variables (aka global, local, or package variables) are effectively shallowly bound.

    What is closure?

    Closure is a notion out of the Lisp world that says if you define an anonymous function in a particular lexical context, it pretends to run in that context even when it's called outside the context.

    What is an anonymous subroutine?

    An anonymous subroutine is a subroutine without a name.

    How do you create a reference to a anonymous subroutine in Perl?

    An anonymous subroutine can be created by using sub without a subname: $coderef = sub { print "Boink!\n" }; Perl creates anonymous subroutines on the fly at run time which explains why anonymous subroutines can be nested and named subroutines which are created at compile time can not be.

    How are closures implemented in Perl?

    Closures are implemented in Perl as anonymous subroutines with lasting references to lexical variables outside their own scopes. These lexicals magically refer to the variables that were around when the subroutine was defined (via deep binding).

    What is a closure capture?

    Closures are subroutines that package all the variables they need from the scope in which they are created. They package these variables by 'capturing' them. In Perl, this means that the closure keeps a reference to each lexical variable it uses declared outside its scope. The closure stops these variables from going out of existence by incrementing their reference count.

    Please allow access to your computer’s microphone to use Voice Recording.

    Having trouble? Click here for help.

    We can’t access your microphone!

    Click the icon above to update your browser permissions above and try again

    Example:

    Reload the page to try again!

    Reload

    Press Cmd-0 to reset your zoom

    Press Ctrl-0 to reset your zoom

    It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

    Please upgrade Flash or install Chrome
    to use Voice Recording.

    For more help, see our troubleshooting page.

    Your microphone is muted

    For help fixing this issue, see this FAQ.

    Star this term

    You can study starred terms together

    NEW! Voice Recording

    This is a Plus feature