From: Anders Selander Date: 2002-02-20T03:40:28+09:00 Subject: Re: Perl IO to Ruby IO help needed On Wed, Feb 20, 2002 at 03:02:04AM +0900, Craig Files wrote: > The Perl file: > > open (DEF, "<$input_def") || die "$0: cannot read $input_def\n"; > $/ = undef; # read the entire file... > $_ = ; # ...into memory > close(DEF); > > $sep = "\003"; # Use cntl-C as a separator between elements > s/\n\s*-\s/\n$sep /g; # replace leading dashes with separator > s/#[^\n]*\n/ /g; # delete comments > s/\s+/ /g; # replace all newlines with space Well, I better start to contribute to the list, as I have recieved help from it myself. ;-) A suggestion of a Ruby version: file = File::readlines(input_def).each { |line| line.gsub!(/^\s*-\s/, "\003") line.gsub!(/#.*$/, " ") line.gsub!(/\s+/, " ") print "#{line}" } I took the liberty to use ^ and $ instead of \n in the regexps. Note that the first regexp only works on single dashed that always are followed by a whitespace. Regards /Selander