?

Log in

No account? Create an account

Previous Entry | Next Entry

nested functions in Perl

As mentioned in the previous post, I found Perl has problems here:

[Zefiris:0] cat unbound.pl
sub outer {
    sub inner {
        print "inside inner\n";
    }
    print "inside outer\n";
}

outer();
inner();

[Zefiris:0] perl unbound.pl
inside outer
inside inner


Perl's inner() enters the global scope, even from within outer()

Vs.

[Zefiris:0] cat unbound.py
def outer():
    def inner():
        print("inside inner")

    print("inside outer")

outer()
inner()

[Zefiris:0] python unbound.py
inside outer
Traceback (most recent call last):
  File "unbound.py", line 8, in 
    inner()
NameError: name 'inner' is not defined


Python does the scoping I expect, though not any compile time checking for undefined functions. Though Perl doesn't here, either, even with 'use strict;'. Well, I suppose it's possible that in these languages, outer() could have done something to define inner() before it was called.

See the comment count unavailable DW comments at http://mindstalk.dreamwidth.org/452901.html#comments

Profile

Phoenix
mindstalk
Damien Sullivan
Website

Latest Month

August 2017
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  

Tags

Powered by LiveJournal.com
Designed by Lilia Ahner