From: William James Date: 2005-09-14T09:36:33+09:00 Subject: Re: Adventures in html decoding. mathew wrote: > William James wrote: > > ARGF is no more esoteric than ARGV, [...] > > I disagree. ARGV is familiar to anyone who's ever written C, C++, > Objective-C, Java, Perl, AWK, Python, Scheme, ... > ARGF is not. These are not familiar to everyone who's ever written in C or Awk: class, map, join, __END__, DATA, < I'd never heard of it until this thread. Major premise: I know everything about Ruby except that which is esoteric. Minor premise: I don't know about ARGF. Conclusion: ARGF is esoteric. > > Compare the number of references to ARGV and ARGF in the pickaxe book > too: ARGF is only mentioned three times in the entire book according to > the index. Pickaxe (1st edition), page 16: The "Ruby way" to write this would be to use an iterator: ARGF.each { |line| print line if line =~ /Ruby/ } on page 219 under the heading "Standard Objects" these are listed: ARGF, ARGV, ENV, false, nil, self, true page 217 explains ARGF's synonym, $<. "Teach Yourself Ruby in 21 Days" explains ARGF in Day 8 on page 173 and uses it in the final two solutions to a problem. The penultimate one is has_a_long_word = /\w{5,}/ ARGF.each{|line| print line unless has_a_long_word =~ line} Matz himself in "Ruby in a Nutshell" explains it on page 38 and lists it as one of 14 predefined global constants. > One of those is in a grey "you can skip this" section talking > about Perlisms, For that the authors should be afflicted with the Spell of Forlorn Encystment. ------------ ------------ Usage tip: the name of the file currently being read is available as $FILENAME or as shown in this example: ruby -e 'ARGF.each{|x| print ARGF.filename + ", " + x }' file1 file2