From kragen@dnaco.net Wed Sep  9 19:40:13 1998
Date: Wed, 9 Sep 1998 19:40:10 -0400 (EDT)
From: Kragen <kragen@dnaco.net>
To: "Bradley M. Kuhn" <bkuhn@ebb.org>
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: <19980909173039.P17438@ebb.org>
Message-ID: <Pine.SUN.3.96.980909192747.16247B-100000@picard.dnaco.net>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Keywords:
X-UID: 1774
Status: O
X-Status: 

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.

> >   <1>               <2>                 <3>                     <4>
> > cat *.plx  |  block_tilde_names  |  print_that_name  |
> 
> First of all, to make this equivalent to the perl script, wouldn't you need 
> 'ls -1 *.plx' for <1>, not cat?

Yes.  Or just ls *.plx, since ls is -1 by default when not writing to a tty.

> And, why would you have to block_tilde_names, as the shell would have
> already done that...only picking up *.plx....Seems superfluous to me...

I wondered the same thing.  Blocking SCCS s.something.plx makes more
sense.

> And, I say again:  $_ has nothing to do with this.  You could have written
> Perl to do it without it:

$_ is not essential, but it's nice to not have to explicitly name all
your variables.

(You probably don't like Forth, either, do you? :)

> Mine reads better, and even works under 'use strict;'.

His doesn't?

> Yours is mildly faster to type, but gives up readability for it.

I don't think so.

> There is a way to solve this, and that is to put 'local($_)' at the top of
> every subroutine that uses it.  However, in practice, I find that people
> don't do this, or they do it, and then get burned on the semantics of
> dynamic scoping.

I *always* do this, because I don't like clobbery subroutines that lead
to subtle bugs later on.

> If you could 'my($_);', I would be much more comfortable with the use of $_.

I'd like that much better, myself.  Then whether your code broke would
depend on whether or not *you* forgot to declare $_ local, not on
whether somebody else whose routine you're calling forgot to declare
$_ local.

> I have never seen $_ used in a maintainable way (which would be to local()
> it everywhere, which no one does).

I do, in every single place where I use it in a subroutine.

I'd offer to give you an account on my machine so you could see, but I
can't do that right now.  I need to finish building some machines so I
can put private data on secured machines.

> 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.  ;)

> $_ just saves typing.  The only place it gives real "expressive power" is in
> things like map(), which actually does $_ right, and makes its own,
> lexically scoped version of $_.

Yes, I use map a *lot*.  I wish it were possible to do map in C and
C++.  

Kragen

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
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


