http://www.perlmonks.org?node_id=108775


in reply to Style & subroutine organization

I'm not clear on what you want to do, but if you want to pass the return value of func1() to func2() and the return value of func2() to func3() then you just have to:
func3( func2( func1() ) );

if you're looking to abuse some perl internals, then you can using the special variable @_ and function passing using &subroutine.
When you call a function like this: &foo; foo is passed the current value of @_. Also, did you know that manipulating @_ inside a function actually manipulates the passed variables? Kinda like pass by reference in c. check this out:
use subs qw/foo bar baz/; @_ = ( 1, 2, 3, 4 ); &foo; # sends current contents of @_ print join(' ', @_), "\n"; &bar; # sends current contents of @_ print join(' ', @_), "\n"; &baz; # sends current contents of @_ print join(' ', @_), "\n"; &baz(); # sends an empty list print join(' ', @_), "\n"; sub foo { map { $_++; } @_; # map actually changes the values in @_ } sub bar { map { $_+=2 } @_; # again, map changes @_ } sub baz { map { $_--; } @_; # also chainging @_; }

I don't know which you're trying to accomplish, but becareful using these tricks as it could have unwanted side effects. Also note that calling a sub routine like this: &foo() over rides the default behaviour of passing @_ to the function and sends it an empty list ().

hope that helps,
-brad..