[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading through files



Steve Kilbane wrote
> rittle@comm.mot.com (Loren James Rittle) replies:
> > for (i= `` \n {cat /etc/passwd})
> 
> Ugh. Well, it works, and it's what I use, but
> it's lousy for use in scripts; es already takes up
> enough memory without snarfing a whole file (including
> putting it into the environment), when you only want
> to look at it one line at a time.

You don't have to put it in a variable.  the example above doesn't.

If you put it into a variable, that doesn't have to be exportd:
let-bound (lexically scoped) variables, function arguments, and
variables listed in $noexport aren't exported.

> One method was to use line. Problem is, you can't tell
> if you've read a blank line or reached the end. This is
> my main bug-bear with rc/es. When I used rc, I used to
> hack each release so that I could do:
> 
> while (x = `line) {
> 	something_with $x
> }
> 
> as you can do with the Bourne shell. I haven't bothered
> with es - I've just used Perl when I know I'm going to
> be processing arbitrarily large files.
> 
> Sigh. I'd still like access to the status of `prog...

Es and rc now return the status of the most recent backquoted command in
$bqstatus.  (Es actually returns it in the first result of $&backquote,
but %backquote stores it in that variable.)

Paul