T
Todd A. Jacobs
I have the following snippet:
at_exit do
$total_count, $daily_count = 0, 0
IO.foreach(my_logfile) do |line|
$total_count.next
$daily_count.next if line =~ /^#{Time.now.strftime('%Y%m%d')}/
end
printf("\ns Total: %d\ns Today:%d\n", $total_count,
$daily_count)
end
I assumed I had to use globals, since otherwise the block would treat
the counters as local variables, but I have the same problem either way:
the counters never increase. They still both read zero at the end of the
script, even though some strategic puts statements show that the file is
successfully being read.
What newbie mistake am I making now?
at_exit do
$total_count, $daily_count = 0, 0
IO.foreach(my_logfile) do |line|
$total_count.next
$daily_count.next if line =~ /^#{Time.now.strftime('%Y%m%d')}/
end
printf("\ns Total: %d\ns Today:%d\n", $total_count,
$daily_count)
end
I assumed I had to use globals, since otherwise the block would treat
the counters as local variables, but I have the same problem either way:
the counters never increase. They still both read zero at the end of the
script, even though some strategic puts statements show that the file is
successfully being read.
What newbie mistake am I making now?