From: Robert Klemme Date: 2004-09-05T04:55:16+09:00 Subject: Re: OK... :) question about hash and array literals "Patrick May" schrieb im Newsbeitrag news:4916C543-FEA8-11D8-81CB-000A95848050@hexane.org... > Hello, > > My main use for using ordered hashes is to express repeated regexp string > transformations. For example, in php I use this series of regexp's to > clean up html spacing: > > foreach( array( '/\n|\f|\r/' => " ", > '/\s+/' => " ", > '/\s*<\/p>/i' => "

", > '/

<( )?\/p>/i' => "", > '/

/i' => "\n\n

", > '/

$/i' => "", ) as $p => $r ) { > $string = preg_replace( $p, $r, $string ); > } > > There are of course other uses, but has been a real handy one for me. In this case nested arrays are sufficient since you don't need efficient lookup. The only access is iteration as far as I can see. Example: transformations = [ [/foo/, "bar"], [/baz/, "xxx"], [/\s+/, " "], ] text = "xxx foo ddddd bar bazsiud" transformations.each {|rx, repl| text.gsub!(rx, repl) } Kind regards robert