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: perl bug with $1, affected by subroutine call Message-ID: <7314@jpl-devvax.JPL.NASA.GOV> Date: 7 Mar 90 18:24:38 GMT References: <7291@jpl-devvax.JPL.NASA.GOV> <7298@jpl-devvax.JPL.NASA.GOV> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 51 In article jbw@bucsf.bu.edu (Joe Wells) writes: : Ok. Let me rephrase what you've said and see if you disagree with it. : : First, the syntax for a subroutine call is like this: : : do SUB ( LIST ) : & SUB ( LIST ) : & SUB : : Second, each item in a LIST is evaluated in an array context. If that : item evaluates to an array, each item of the resulting array is added to : the list, otherwise the single resulting scalar item is added to the list. : : Is this a correct restatement, or am I still missing something? You're right on the money. : : Since the "if" is the last statement of the sub block, it has to be : : evaluated in the context that the subroutine was called. : : : : Huh? Does this mean that an "if" statement has a value, unlike in C? If : : so, is there a precise specification of the value of an "if" statement? I : : can't find that in the manual. : : If you look up subroutines you find: : : do SUBROUTINE (LIST) : Executes a SUBROUTINE declared by a sub declaration, : and returns the value of the last expression : evaluated in SUBROUTINE. : : What was the last expression evaluated in your subroutine? : : Not the conditional of the "if" statement! Ok, you're right, it wasn't the last expression, since the conditional turned out to be true. But it would have been last if the conditional had been false. And there's no way to tell beforehand. But you have to supply the context to an expression before it gets executed. Catch 22. There's a possible problem with forcing the context of a conditional EXPR to scalar. If we force it, then when it doesn't match it will return what looks to the subroutine as a non-null array value, i.e. (''). So if in calling the subroutine they say if (@retval = &mysub()) { then they'll get a true indication from the array assignment, even though the only value in the array is false. Time to think s'more... Larry