Stewart Stremler wrote:
> begin  quoting John H. Robinson, IV as of Mon, Sep 11, 2006 at 01:26:06PM 
> -0700:
> > Carl Lowenstein wrote:
> [snip]
> > > OK, but somewhere you have lost the requirement to exclude
> > > "\.google\.com$" from the exclude_list.  So a pipe to "grep -v" is
> > > called for, or else you can say "oops, I have to edit exclude_list
> > > before I actually use it."
> > 
> > Yes, I did overlook that requirement. Update:
> > 
> > $ set `lynx -dump http://www.google.com/supported_domains`
> > $ shift
> > $ while [ $1 ]; do echo "RewriteCond %{HTTP_REFERER} ^http://www$1 [OR]"; 
> > shift; done > exclude_list
> 
> ... And now you might as well put it into a file, format it so you get
> one statement per line, etc. etc.

I consider this to be completely throw-away, so, no. No need to put it
into a file. Maybe into a collection of ``interesting'' one-liners, but
I don't consider this to be terribly interesting. Actually, it is about as
dull as it gets: foreach entry, print it with some additional text on a
line. That is _slightly_ better than

10 FOR I IN 1 TO 20
20 PRINT $I
30 NEXT

but not by much.

> After all, too much typing means I'm likely going to make a typing
> error, which wastes more of my time in the long run.
> 
> "Reasonable" varies per person, no doubt.

Of course. My main metric is _complexity_. A single for loop is not
terribly complex. Even the backticks were not complex, as it was a
single command. There was an url (cut and pasted) and the boilerplate
text (agan, cut and pasted).

If allowed to use variables for them - as you did - we'd get

$ for i in `lynx -dump $u`; do echo "$t$i [OR]"; done > exclude_list

Well below the 80 character limit. Replace the $u and $t with the
cut/n/paste, and you see what I mean. That was the wrong output, of
course. Doing it The Right Way (excluding the www.google.com) made
things More Complex and outside the scope of a One-Liner.

$ for i in `lynx -dump $u`; do echo "$t$i [OR]"; done | sed '1d' > exclude_list

Even with the correct output, I can still get < 80 characters. At the
expense of a call to sed. Again, replace $u and $t with the
cut/n/pastes. Someone else provided it, why re-type it?

Strictly speaking, the ''s arounf the 1d are not required, but they do
make the sed command more readable, in my opinion. As do the spaces.

But you have to admit, avoiding a call to grep or sed is a good thing! If
google were to re-order http://www.google.com/supported_domains then my
examples could easily fail.

But it is a one-off, throw-away ``script'', so who cares, right?

-john

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to