Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: To call a sub from another sub

by Anonymous Monk
on Feb 02, 2006 at 11:55 UTC ( #527310=note: print w/ replies, xml ) Need Help??


in reply to Re: To call a sub from another sub
in thread To call a sub from another sub

I would like that subrutine1 sbould get a value from subrutine2, It should process this value and return the result to subrutine2. Is this possible or do I have to pass subrutine1 to subrutine2?


Comment on Re^2: To call a sub from another sub
Re^3: To call a sub from another sub
by jkva (Chaplain) on Feb 02, 2006 at 12:02 UTC
    Perhaps you want this :
    sub subroutine_1 { my $val = subroutine_2(); print "$val this is subroutine_2 output!"; } sub subroutine_2 { return "w00t!"; }
    It does not pass it back to subroutine_2 but should give you a rough idea of how things like these work.
      Two points:
      • You missed the part where a value is passed in, processed, and returned.
      • Don't just hand him complete working code. He made no attempt to write any code himself, and he won't learn anything until he does, and it's obviously homework, the first assignment of the semester by the look of it.
Re: To call a sub from another sub
by jonadab (Parson) on Feb 02, 2006 at 12:19 UTC
    Yes, it'll work just fine. It will even work if the outer subroutine is a lexical closure and passes the other subroutine one of the lexically-retained references it is holding, like this:
    sub :: {return lc pop} sub jonadab { my $lex = shift; @ARGV=qw(http://); return sub{ my ($ical) = @_; my $closure = :: $lex.".".$ical."/".$/; }} my $foo = jonadab("PerlMonks"); $\=$foo->("Org"); print shift;

    Note: if you turn in code like that for homework, don't expect a good grade.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527310]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-27 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls