Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!mit-eddie!bu.edu!nntp-read!jbw From: jbw@bucsf.bu.edu (Joe Wells) Newsgroups: comp.lang.perl Subject: Re: perl bug with $1, affected by subroutine call Message-ID: Date: 6 Mar 90 20:15:20 GMT References: <7291@jpl-devvax.JPL.NASA.GOV> Sender: news@bu.edu.bu.edu Organization: Boston University Computer Science Department Lines: 46 In-reply-to: lwall@jpl-devvax.JPL.NASA.GOV's message of 6 Mar 90 17:18:52 GMT In article <7291@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: In article jbw@bucsf.bu.edu (Joe Wells) writes: : When the this short perl program is run: : : &one(&sub1); : &sub1; : : [stuff deleted] : : Would anyone happen to know why $1 is not getting set properly in : &one(&sub1)? Yes. It's because in the first case you're calling sub1 in an array context, and in the second, a scalar context. Huh? Why is "&sub1" in "&one(&sub1)" being evaluated in an array context? I intended it to be the single scalar argument to "&one". 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 an "if (EXPR) BLOCK" statement is evaluated in a certain context, does that mean that EXPR is always evaluated in the same context? It seems that EXPR should always be evaluated in a scalar context, and the value of the "if" statement should be the value of BLOCK (evaluated in the appropriate context). So the /(x)/ has it's array context behavior. Question about this. Consider this statement: @a = /xxxxxxx/; What is the value of @a if the match succeeds? (), right? What is the value of @a if the match fails? (), right? Confused in Boston, -- Joe Wells