# Memo to self

**URL:** <https://www.ruby-forum.com/t/memo-to-self/70688>\
**Category:** Ruby\
**Created:** [February 20, 2006, 3:20am UTC](https://www.ruby-forum.com/t/memo-to-self/70688 "2006-02-20T03:20:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [February 20, 2006, 3:20am UTC](https://www.ruby-forum.com/t/memo-to-self/70688/1 "2006-02-20T03:20:18Z")

</div>

Never under estimate what you can achieve with  
IO.read( “filename”).scan(%r{}mx) do |match|  
end

Especial as you can control how greedy the regex is with .\*?

I just deleted a lot of code and replaced it with one line.

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

Carter’s Clarification of Murphy’s Law.

“Things only ever go right so that they may go more spectacularly wrong  
later.”

From this principle, all of life and physics may be deduced.

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [February 20, 2006, 3:23am UTC](https://www.ruby-forum.com/t/memo-to-self/70688/2 "2006-02-20T03:23:21Z")

</div>

John C. wrote:

> Never under estimate what you can achieve with  
> IO.read( “filename”).scan(%r{}mx) do |match|  
> end
> 
> Especial as you can control how greedy the regex is with .\*?
> 
> I just deleted a lot of code and replaced it with one line.

Well, as your self.memo included the rest of us, how about  
sharing the example?

Hal

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [February 20, 2006, 12:39pm UTC](https://www.ruby-forum.com/t/memo-to-self/70688/3 "2006-02-20T12:39:53Z")

</div>

John C. wrote:

> PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
> New Zealand
> 
> Carter’s Clarification of Murphy’s Law.
> 
> “Things only ever go right so that they may go more spectacularly wrong later.”
> 
> From this principle, all of life and physics may be deduced.

# Read and parse the first file on the command line.

gets(nil).scan( //mx ) { |s|  
}

# Read and parse the rest of the files.

ARGF.read.scan( //mx ) { |s|  
}

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [February 23, 2006, 2:20am UTC](https://www.ruby-forum.com/t/memo-to-self/70688/4 "2006-02-23T02:20:13Z")

</div>

On Mon, 20 Feb 2006, Hal F. wrote:

> sharing the example?  
> Ok. Just quickly. I had a file of the format…

blah  
blah  
Command :  
some stuff  
some more stuff I   
want with line continuation   
characters

blah  
blah  
Command :  
more some stuff  
more some more stuff I   
want with line continuation   
characters

blah  
blah  
…

that I wanted transformed into  
some stuff  
some more stuff I want with line continuation characters  
more some stuff  
more some more stuff I want with line continuation characters

So I started write a routine to fix up the \ characters yield fixed  
lines and then a state machine to search for ‘Command:’ and gather  
everything until the blank line and then skip until…

I start playing with Generator since I realised I could then keep  
everything in a  
each\_something do |thing|  
yield other\_thing( thing)  
end  
pattern instead of doing state machines and then I threw everything away  
and replaced it with…

```
File.read( "big_file").scan(%r{\nCommand\ :\n(.*?)\n\n}mx) do 

```

|command|  
puts $1.gsub( %r{\\n}mx, ‘’)  
end

and then  
everyone.send( :memo, “to self”)

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

Carter’s Clarification of Murphy’s Law.

“Things only ever go right so that they may go more spectacularly wrong  
later.”

From this principle, all of life and physics may be deduced.
