in reply to Safe module and undefined subroutines
Hello bovlb,
Welcome to the Monastery. Just a minor note to make here. You have not answered the question of Anonymous Monk What problem are you trying to solve with it?.
Why you want to call one subroutine as a parameter within another one? If you want to call a local subroutine withing another subroutine why you do not call it like this?
#!/usr/bin/perl use strict; use warnings; use feature 'say'; sub a { say 'sub a'; local *_b = sub { say 'sub b'; }; _b(); } a(); __END__ $ perl test.pl sub a sub b
Update: You can make it even more complicated if you want.
#!/usr/bin/perl use strict; use warnings; use feature 'say'; sub a { local *_b = sub { say @_; return 'sub b'; }; return _b('sub a'); } say a(); __END__ $ perl test.pl sub a sub b
Update2: You can make it even more complicated if you want, which is like calling a subroutine withing another subroutine a(_b()).
#!/usr/bin/perl use strict; use warnings; use feature 'say'; sub a { local *_b = sub { return @_; }; return _b(@_); } say a('sub a'); __END__ $ perl test.pl sub a
You can read more about this from this question Defining a sub within a sub: OK?. Tell us what you are trying to achieve? Many people here (not me) are very experienced so they can help you in many areas / ideas.
Looking forward to your update, BR.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Safe module and undefined subroutines
by 1nickt (Canon) on Aug 25, 2017 at 12:20 UTC | |
by thanos1983 (Parson) on Aug 25, 2017 at 13:25 UTC | |
by 1nickt (Canon) on Aug 25, 2017 at 15:05 UTC |