thanks in advance! I will send out final program once it’s
done.
$ cat <<-EOT >foo.rb
filename = ARGV[0]
this is a test
File.open(filename) {
>file>
# some more test
file.each_line {
>line> # this shouldn’t get removed
next if line =~ /^\s*#/
next if line =~ /^\s*$/
puts line
}
}
EOT
$ ruby foo.rb foo.rb
filename = ARGV[0]
File.open(filename) {
>file>
file.each_line {
>line> # this shouldn’t get removed
next if line =~ /^\s*#/
next if line =~ /^\s*$/
puts line
}
}
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
: > Hi,
: >
: > In message "grep regex to ruby regex..."
: > on 02/07/03, Todd Holloway <todd@duckland.org> writes:
: >
: > |I'm just about to finish up my first ruby program, but I'm
: > |stuck on one last part...I need equivlent of the below in ruby:
: > |
: > |grep -v "^[[:space:]]*#" filename | grep -v '^[[:space:]]*$'
: >
: > File.foreach(filename) do |line|
: > next if /^\s*#/ =~ line
: > next if /^\s*$/ =~ line
: > print line
: > end
:
: ruby -lne 'print unless /\s*#/ or !/\S/' filename
:
: I'm golfing with the champ!
:
Except matz wins because the oringal poster wants it as part of a
ruby program _not_ a one liner ruby program
Regards,
Chris
···
On Tue, 02 Jul 2002 20:35:13 Paul Duncan wrote:
: * Yukihiro Matsumoto (matz@ruby-lang.org) wrote:
--
+------------------------------------------------------------------+