in reply to Help with Time

TheAnswer1313:

Here are a couple of hints:

I offered hints rather than the answer because I believe that you'll want to learn perl quickly so you can edit these scripts you've apparently inherited. And there's no better way than diving in and investigating the code. Of course, a couple of hints here and there about what to look at first can be a real timesaver.... ;^) If you *really* just want the answer, let me know....

...roboticus

Replies are listed 'Best First'.
Re^2: Help with Time
by TheAnswer1313 (Initiate) on Apr 21, 2008 at 15:44 UTC
    I really want the answer lol.
    I thought I could just change the line for ($t = $start; $t < $now; $t += 60*60*24) { to for ($t = $start; $t = $now; $t += 60*60*24) {
    If I just change the $start time tho.....wouldnt I still have to change the $now line as well? I dont know.....Im confused. I just wanted this file to spider my baseball data for me to save time......since manually downloading the files would take forever lol.
      TheAnswer1313:

      OK ... the first lines of your code are choosing the first day to download, 3/31/08 in this case:

      # get all important files from MLB.com, 3/31/08 through yesterday #$start = timelocal(0,0,0,31,2,108); $start = timelocal(0,0,0,31,2,108);

      Read up on the timelocal function if you need more explanation of this part. In fact, read up on timelocal before continuing, or the next bit won't make sense.

      You want to start downloading "yesterdays" file, instead of that hardcoded date. So you need to figure out how to get yesterday's date in the same format that timelocal is going to give it to you (so you don't need to change the code).

      It turns out that timelocal returns the number of seconds since XXXXX. The time function returns the *current* date/time also in seconds since XXXXX. So time almost gives you what you want. Since there are 24 * 60 * 60 seconds in a day, if you subtract that from time, you'll get the same time yesterday. So you could change the lines above to:

      # Start downloading from yesterday $start = time - 24*60*60;

      The rest of the code (including $now) should be just fine. I hope this helps!

      ...roboticus

      Note: The XXXXX is a specific date, but it's unimportant, so I didn't bother to specify.

      Update: Added bit about $now.

        Thanks. That worked in that it started from yesterdays date (Exactly how im wanting it to)......one thing tho........it didnt stop.....it just kept going to the end of the season (tho no data is present obviously, mlb must have those directories set up already).... so anyway to make it start and stop at yesterday's date? Update: Nevermind I got it :)
        Thanks. I'll run it tonight to see if it works :) Although im generally interested in learning about databases such as mySQL etc. What would be a good place for someone to start if they wanted to learn about perl?