0
当我慢慢地写我的日志脚本时,我碰到了一些障碍。我已经完成了大部分程序的工作,但现在我只是添加了一些生物舒适性,例如对可以输入什么以及什么的限制。红宝石清洁用户输入
def HitsPerMinute()
print "Is there a specific hour you would like to see: "
STDOUT.flush
mhour = spectime = gets.strip
#mhour = mhour.to_s
if mhour == '' or mhour == '\n' or (mhour =~ /[a-z]|[A-Z].*/)
puts "Please enter an hour you would like to see."
HitsPerMinute()
#else
#mhour = mhour.to_i
end
mstart = 00
mend = 59
mstart.upto(mend) { |x|
moment = "#{rightnow}:#{zeroadder(mhour)}:#{zeroadder(x)}".strip
print "Server hits at '#{moment}: "
puts `cat /home/*/var/*/logs/transfer.log | grep -C#{moment}`
x = x.to_i
x = x.next
}
end
HitsPerMinute()
大多数情况下,它工作正常,除了它似乎存储之前输入的变量。如这里所示。
Is there a specific hour you would like to see:
Please enter an hour you would like to see.
Is there a specific hour you would like to see:
Please enter an hour you would like to see.
Is there a specific hour you would like to see: d
Please enter an hour you would like to see.
Is there a specific hour you would like to see: 13
Server hits at '10/Oct/2012:13:00: 48
[...]
Server hits at '10/Oct/2012:13:59: 187
Server hits at '10/Oct/2012:0d:00: 0
Server hits at '10/Oct/2012:0d:01: 0
[...]
Server hits at '10/Oct/2012:0d:57: 0
Server hits at '10/Oct/2012:0d:58: 0
Server hits at '10/Oct/2012:0d:59: 0
Server hits at '10/Oct/2012::00: 0
Server hits at '10/Oct/2012::01: 0
[...]
我对我的输入变量使用.strip,但似乎没有为这个问题做任何事情。我尝试使用.flush,但似乎也没有做太多。它甚至如何存储多个变量?
我不得不问,它是如何存储多个变量的?它没有被设置为一个数组,如果将它们存储为'\ n d \ n13',我会感到非常惊讶。 – SecurityGate
我更新了答案,希望它有助于理解它 –