From: Robert Klemme Date: 2010-02-11T01:13:14+09:00 Subject: Re: How to change stdin separator (perl vs ruby) 2010/2/10 Daniel Bye : > On Thu, Feb 11, 2010 at 12:23:55AM +0900, Sak .. wrote: >> I have to process very very big text files and not line per line, I have >> to access to a group of lines seperated for a "%". Then I tryed to >> access line per line and detect the separator for each line saving the >> lines in a buffer, obviously it works but it's very slow (text files are >> bigger than 1GB). >> >> Perl have an awesome feature that is to change the separator for >> iterating files (by default in all languages is "\n"), this simple and >> extremely efficent code do what I need: >> >> $/ = "%"; >> while ($article = ) { >>   #Iteration >> } >> > > If your delimiter only occurs as a delimiter, and not in the data as well: Note that this statement is true for \n as well! > File.open(path_to_file, 'r') do |f| >  f.each('%') do |record| >    # Do stuff. >  end > end You can have it simpler: File.foreach path, '%' do |record| # so something with record end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/