From kragen@dnaco.net Thu Sep 10 08:02:55 1998 Date: Thu, 10 Sep 1998 08:02:54 -0400 (EDT) From: Kragen To: "Bradley M. Kuhn" cc: clug-user@clug.org Subject: Re: $_ would be ok if I could my $_ (was Re: Story about a literary culture of Unix) In-Reply-To: <19980909195852.D7107@ebb.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Keywords: X-UID: 1778 Status: O X-Status: On Wed, 9 Sep 1998, Bradley M. Kuhn wrote: > Thus spoke Kragen: > > On Wed, 9 Sep 1998, Bradley M. Kuhn wrote: > > > Thus spoke James M. Carter: > > > > > > and the FIFO pipes we use to link commands:This piping is an analogue of > > > > > > sorts for perl's $_ (current, default, implied variable). > > > > > > My point was, $_ has nothing to do with STD(IN|OUT|ERR). > > > Sure it does. Both are ways of tossing data around without explicitly > > giving it a name. > > The only thing in Perl where you don't have to name STD(IN|OUT|ERR) is the > <> operator.... Yes, but in sh you never have to name std{out,in,err} at all unless you're doing weird things with them. The sh command line below uses the stdout of three processes and the stdin of three processes without naming any of them. > > > > <1> <2> <3> <4> > > > > cat *.plx | block_tilde_names | print_that_name | > > > > Yours is mildly faster to type, but gives up readability for it. > > > > I don't think so. > > Why not? I think it has more text in it, but the text is noise text -- it doesn't add any readability. > Allow me to rewrite what you said without using the world 'local': > > "I'd like that much better, myself. Then whether your code broke would > depend on whether or not *you* forgot to scope $_ properly, not on whether > somebody else whose routine you're calling forgot to scope $_ properly." Sounds good. > This is where my $_ would be nice....I don't want Bar to know I was using > $_. Well, if Bar does a local $_, then it doesn't matter. If Bar doesn't local $_, it shouldn't be using $_. In any case, Bar shouldn't read $_ unless it writes to it first. (Occasionally I have actually written one-line subroutines that actually do their data passing through $_. This is gross, and should be avoided.) > > > Really, in a way, I am saying having a *global variable* be the default > > > argument to most functions is what is bad. > > > > So maybe you *do* like Forth, then. ;) > > I don't know Forth. :( A Forth program is mostly a list of routine names to call. All of them take their arguments off the stack and put their return values on the stack. The only local variables are on the stack, and therefore entirely nameless. This is similar to PostScript. (Except that PostScript has a built-in associative array type that you can create to use for local variables.) (It's actually a little more complex than this, because you need control flow, but that's the essence of it.) Kragen -- Kragen Sitaker I don't do .INI, .BAT, .DLL or .SYS files. I don't assign apps to files. I don't configure peripherals or networks before using them. I have a computer to do all that. I have a Macintosh, not a hobby. -- Fritz Anderson