in reply to Re^2: getting a subroutine's name
in thread getting a subroutine's name

this code would work fine even if that caller assignment in list context is commmented out since caller works in list and scalar context as well.

Yes, it "works", but it does not return what is expected - the sum of the values passed in.

in the second code however, the problem arises since I am putting a subroutine call inside a subroutine of its own, and the same exact code is here in the book and the return value is supposed be so I am wondering if there is something different

caller works fine in subroutine chains, but the subroutines must be called, which you don't do in your "second code."

Try the following:

sub calling { $value = addem(2,2); } sub addem { ($value1, $value2) = @_; print join(",", caller 0); $value1+$value2; } # this is the missing piece to make the above output something. # call the subroutine! calling();

Replies are listed 'Best First'.
Re^4: getting a subroutine's name
by biohisham (Priest) on Jul 17, 2009 at 19:52 UTC
    OoPs.. :p, that jumped over my head when you said try calling() I thought calling was like another function similar to caller....never mind this stupidity...hehe..thanks a lot anyways...you saved me from myself
    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind