Craig Files wrote:

> Hi,
> 
>  I want to convert the following lines from Perl to Ruby. 


> open (DEF, "<$input_def") || die "$0: cannot read $input_def\n";
> $/ = undef;		# read the entire file...
> $_ = <DEF>;		# ...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


Something like

begin
   open(ARGV[0],'r') do |file|
     @lines = file.readlines
   end
rescue
   raise "cannot read #{ARGV[0]}"
end

@lines.map! do |line|
   (line.gsub /\A\s*-\s/,"\003").
         gsub /\n/, " "
end

out = @lines.select do |line|
   not(line =~ /\A\s*#.*\z/)
end

Tobi

-- 

* peace&love.
* http://www.pinkjuice.com/