Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: subroutine inspecting its calling environment Message-ID: <7283@jpl-devvax.JPL.NASA.GOV> Date: 6 Mar 90 01:57:15 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 31 In article jbw@bucsf.bu.edu (Joe Wells) writes: : Some questions for the great perl gods: : : 1. Can a subroutine tell whether it was invoked without arguments? : : example: &subroutine_name; Not that I know of. : 2. Can a subroutine tell whether it was invoked in an array or scalar : context? Yes, that's what the wantarray operator tells you. : A boolean scalar context? No such animal in Perl. : 3. Can a subroutine tell whether its invocation was part of an expression : or was the entire expression? : : example: &sub($x); : $x = (&sub ($x) + &sub2 ($y)); No. And you can't even tell that the value of &sub($x) above is unwanted without more context, since the last expression in a block might return it's value to the outside of the block. So, no, you can't cheat much... :-) Larry