from my understanding is a nested def in Python equivalent to °
sub outer {
my $c_inner = sub { print "perl" };
$c_inner->();
}
Please note that Python is implicitly preferring references while Perl prefers the "Explicit is better than implicit" approach (yes it's ironic)
> Python has Local, Enclosing, Global and Built-in variables.
More or less: *
- Local and Enclosing correspond to
lexical private vars similar³ to my
- Global corresponds to an our in main:: namespace
- Built-in is CORE:: namespace, (and pretty dangerous to play with)
> It was this video that promoted my thinking on this. https://www.youtube.com/watch?v=QVdf0LgmICw
Not linkified not watched.²
Hint: Please provide code examples if you want better answers.
update
°) There was an experimental attempt to allow "private subs" in Perl, which was essentially syntactic sugar for the following IIRC. No idea if it's still available or deprecated.
*) the py-docs are sparse and incomplete here. Variable declarations in class context become attributes. These are essentially package vars in Perl. (Python has no package and Perl has no class )
²) tried to, but won't watch a 20 min video to guess what your question is.
³) updated, see Re^7: Nesting Functions for details |