Can I embed subroutines? - Page 3

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Can I embed subroutines?

On 1/8/2015 10:39, T wrote:
Quoted text here. Click to load it

of course you can embed subroutines recursive , for ever ... here is how  
to do it

use strict; use warnings; use feature 'say';

no warnings "experimental::lexical_subs";
use feature 'lexical_subs';

my  sub foo { 'outer local  foo' }
our sub bar { 'outer global bar' }


sub Sabroutine
# call the outer bar    
say bar();

my sub bar { 'inner local    bar' }
# call the inner bar    
say bar();

# call the outer bar
say &main::bar();


Re: Can I embed subroutines?

On 08/04/2015 02:35 PM, George Mpouras wrote:
Quoted text here. Click to load it

Okay.  You can do it with "my" variables set up to
reference (point) to the subroutines.

The way I have always seen it before (Pascal, Modula2)
was to just include a sub inside another sub.  When you
did that, no one else except the sub it was embedded
in could see it.

No big deal.  I just have top be careful what I call my
subs that are called by others subs.

Thank you for helping me with this!


Site Timeline