From: Sean Russell Date: 2002-05-30T05:03:26+09:00 Subject: Regexp in ranges as control I've always liked the syntax: while gets print if /start/../end/ end However, on a recent project, I tried to extend this concept: lines.readlines("somefile").each do |line| puts line if line === /start/../end/ end This doesn't work, and I don't know why. I can /get/ it to work, with lines.readlines("somefile").each do |$_| puts $_ if /start/../end/ end but I have to say that this really, really makes me uncomfortable. Do I /have/ to use the global variable $_ just to use regexps as switches? Why? You don't need them for other ranges. For example, the following works: [1,2,3,4,5,6].each do |x| puts x if x === 3..5 end ruby 1.6.6 (2001-12-26) [i586-linux-gnu] Thanks. -- |.. "ROM stands for Read-Only Memory, meaning that new things cannot be <|> written to it; ROM is the silicon equivalent of the brain of a /|\ religious fanatic." /| -- Lincoln Spector |