in reply to Re^4: sub fuction inside sub functioin?
in thread sub fuction inside sub functioin?
but using the global namespace for an inner function is somehow dangerous. What if you call an external function within outer, that tries to call a completely different function also called inner()?
First, there's no such thing as the global namespace. The code uses the current namespace.
Secondly, are you seriously complaining that a script can't have two functions with the same name? Or did you mean to test something like
use strict; use warnings; $\ = "\n"; sub outer2 { local *inner = sub { print "inner_of_outer2" }; inner(); } sub outer1 { local *inner = sub { print "inner_of_outer1" }; inner(); outer2(); } outer1();
Unfortunately, that gives a warning.
inner_of_outer1 Subroutine main::inner redefined at script.pl line 7. inner_of_outer2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: sub fuction inside sub functioin?
by LanX (Saint) on Dec 08, 2008 at 02:05 UTC | |
by ikegami (Patriarch) on Dec 08, 2008 at 02:52 UTC | |
by LanX (Saint) on Dec 08, 2008 at 02:56 UTC | |
by ikegami (Patriarch) on Dec 08, 2008 at 03:09 UTC | |
by LanX (Saint) on Dec 08, 2008 at 11:10 UTC | |
| |
|
Re^6: sub fuction inside sub functioin?
by gone2015 (Deacon) on Dec 08, 2008 at 02:08 UTC |