Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!elroy!devvax!lwall From: lwall@devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.d Subject: Re: How are YOU using perl? Message-ID: <1876@devvax.JPL.NASA.GOV> Date: 22 Apr 88 19:11:00 GMT References: <235@ateng.UUCP> <42400006@uicsrd.csrd.uiuc.edu> Reply-To: lwall@devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 68 In article <42400006@uicsrd.csrd.uiuc.edu> mcdaniel@uicsrd.csrd.uiuc.edu writes: : : 1) there is no way to declare local names. To avoid name collisions : in "sub"s I was prefixing names with the "sub" name, which lead to : lines like : : for ($SWAP_i = 0; $SWAP_i < $#lru_buffers; $SWAP_i++) I agree, that's painful. Currently I'd use pushes and pops to make local variables, but I'm planning to make a "local" operator of some sort. For now: sub FOO { push(@STK,$i,$j,$k); ... ($k,$j,$i) = (pop(@STK), pop(@STK), pop(@STK)); } But someday soon: sub FOO { local($i,$j,$k); ... } All it does internally, of course, is to push $i, $j and $k on a stack, and restore them automatically upon exiting the block in which they are pushed. The local operator would probably be an lvalue, so you could say sub FOO { local($x, $y, $z) = @_; # name formal parms local($i, $j, $k); # push locals ... } Can you think of a better way to do this? : 2) If I make a typo in a variable name, I get no compiler- or run-time : notice except for wrong answers. Icon has a partial solution: an : option makes all new variables start with a special value, : which causes a run-time error if used before setting. This gets many : of the cases, but you can still sometimes use a typo-ed name on the : LHS of an assignment without warning. Only declarations can catch : those. It will be fairly easy to add a similar option to perl. In fact, it'll take about 10 minutes. How about a warning on variables that are only mentioned once, either as lvalue or rvalue? Probably tied to the same option. How about -w for "warn"? : For a short program, all the identifiers are there in front of you, : and it's easier to see and avoid such problems. Furthermore, perl's : typelessness (which I like) and lack of declarations help---you can : get off the ground without all the overhead of typing (in either : meaning of the word). But after 175 lines of perl, I decided that : putting up with C (despite mucking about with and sscanf : and malloc and pointers and . . .) was easier. : : However, I *will* use perl in shorter applications. Perl isn't intended for long applications. You'll note that I write long applications in C also. On the other hand, I don't want to place arbitrary restrictions on long scripts just because I'm mean and nasty. Larry Wall lwall@jpl-devvax.Jpl.Nasa.Gov