Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:53:56+00:00 2026-06-13T02:53:56+00:00

As I’m slowly writing my logging script, I’ve hit sort of a snag. I’ve

  • 0

As I’m slowly writing my logging script, I’ve hit sort of a snag. I’ve gotten the bulk of the program to work, but now I’m just adding in some creature comforts, such as some limits on what you can enter and whatnot.

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()

For the most part it works fine and well, except it seems to store the variables that are entered before. As shown here.

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
[...]

I use .strip on my input variables, but that doesn’t seem to do anything for this issue. I tried using .flush but that doesn’t seem to do much either. How is it even storing multiple variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:53:58+00:00Added an answer on June 13, 2026 at 2:53 am

    the HitsPerMinute method is called several times, when the if condition ends it continues the run, do it in a loop instead

    def HitsPerMinute()
    
      STDOUT.flush
      mhour = ''
    
      while mhour == '' or mhour == '\n' or (mhour =~ /[a-z]|[A-Z].*/) do
        puts "Please enter an hour you would like to see."
        mhour = spectime = gets.strip
      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()
    
    • update about variables:

    it is not storing several values on mhour variable, mhour has only one value each time the method is called. User is answered to enter a new value before the method reaches its end, so when it finally ends, the previous calls continue its run, maybe this example helps to understand:

    def method(i)
      if i < 5
        method(i+1)
      end
      puts i
    end
    
    method(1)
    

    output:

    $ ruby /tmp/test.rb
    5
    4
    3
    2
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.