From: Craig Files Date: 2002-02-20T05:37:49+09:00 Subject: Re: Perl IO to Ruby IO help needed On Tue, 19 Feb 2002 11:51:44 -0700, Tobias Reif wrote: Thanks to you and Mike Stok, Boy was I over thinking this problem! > 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... $_ = ; # ...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 > -- ___________________________________________________________________________ Craig Files, PhD | / http://coxcomb.ftc.agilent.com/~cfiles/ | __o / craig_files@agilent.com | \<, / ____________________________________________|_____()/ ()____/ (970)288-0183