Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!husc6!bu.edu!nntp-read!composer From: composer@bucsf.bu.edu (Jeff Kellem) Newsgroups: comp.lang.perl Subject: Re: "MOST COMMON NOVICE BUG" contest Message-ID: Date: 13 Mar 90 20:42:28 GMT References: <15230@bfmny0.UU.NET> <15232@bfmny0.UU.NET> <1118@etnibsd.UUCP> Sender: news@bu.edu.bu.edu Reply-To: composer@cs.bu.edu Organization: Boston Univ., Computer Science Lines: 44 In-reply-to: tom@ssd.csd.harris.com's message of 12 Mar 90 12:19:11 GMT In article tom@ssd.csd.harris.com (Tom Horsley) writes: > Date: 12 Mar 90 12:19:11 GMT > > My most confusing bug as a novice user was believing that local() provided > some form of lexical scoping when what it really does is just push a new > definition for things with that name. I finally figured this out after > trying to debug something that looked like: > > sub fred { > local($barney); > ... > } > > ... > > do fred($barney); > > It took me a long time to figure out why my subroutine 'fred' was never able > to get to the value I thought I passed as the parameter... Well, not exactly. You forgot to assign the @_ array (the args to the sub) to $barney. Probably what you wanted is something like... sub fred { local($barney) = @_; ... } then... do fred($barney); should do what you want. Cheers... -jeff Jeff Kellem INTERNET: composer@cs.bu.edu (or composer@bu.edu) UUCP: ...!harvard!bu-cs!composer