[ale] [OT] Variation of grep

JK jknapka at kneuro.net
Thu Mar 12 14:28:38 EDT 2009


Ed Cashin wrote:
> On Wed, Mar 11, 2009 at 6:27 PM, JK <jknapka at kneuro.net> wrote:
> ...
>> (Bring on the perl one-liners...)
> 
> My perl is rusty.  I can't remember it's equivalent to ruby's "scan".
> 
> ruby -e 'gets(nil).scan(/CUSTOMER.*?\/CUSTOMER/m).each {|i| puts i if
> i =~ /STATE: WA/m }' /tmp/dat
> 
> That works fine unless /tmp/dat is big.  Does your current python
> implementation slurp the whole input into memory like this one-liner?

No.  It uses file.xreadlines(), which creates an iterator that reads from
the file on demand.

However, I'd be surprised if a similar facility didn't exist in Ruby.
That one-liner is enough to get Ruby into my "next-language-to-learn"
slot. After Haskell, which I'm working on now.

-- 
I do not particularly want to go where the money is -
  it usually does not smell nice there. -- A. Stepanov


More information about the Ale mailing list