in reply to Re: Forward declaration of subs
in thread Forward declaration of subs
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)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Forward declaration of subs
by BrowserUk (Patriarch) on Oct 12, 2013 at 01:47 UTC |