Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Forward declaration of subs

by BrowserUk (Pope)
on Oct 11, 2013 at 23:21 UTC ( #1057958=note: print w/replies, xml ) Need Help??


in reply to Forward declaration of subs

Is there any practical application of forward declaration of subroutines?

Yes. If you have mutually recursive subroutines -- sub a calls sub b; and sub b calls sub a; -- then you need to forward declare one of them to pass strict, if you want to avoid using parens.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Forward declaration of subs
by LanX (Chancellor) on Oct 12, 2013 at 00:24 UTC
    > mutually recursive subroutines ... if you want to avoid using parens.

    As an illustration, the following doesn't work cause &b is unknown when &a is compiled.

    Without strict b will be converted to string "b" and returned. (strict prohibits this behaviour of barewords.)

    lanx@nc10-ubuntu:/tmp$ perl sub a { print "a$level "; b if $level-- }; sub b { print "b$level "; a if $level-- }; $level=5; print"\n"; a; print"\n"; b; __END__ a5 b4 a3

    with forward declaration

    lanx@nc10-ubuntu:/tmp$ perl sub b; sub a { print "a$level "; b if $level-- }; sub b { print "b$level "; a if $level-- }; $level=5; print"\n"; a; __END__ a5 b4 a3 b2 a1 b0

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Better addressed to the OP.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057958]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2016-12-06 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (96 votes). Check out past polls.