in reply to Re: Help with Time
in thread Help with Time

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.

Replies are listed 'Best First'.
Re^3: Help with Time
by roboticus (Chancellor) on Apr 21, 2008 at 16:42 UTC
    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?

        I'm glad you got it going! As regards to a good starting source for learning perl, I couldn't help you. I've programmed in too many languages before moving to perl, so I just started working on other people's programs, constantly using the perldoc command to figure out what *this* or *that* means. (In fact, I still don't really know perl ... I've never built any OO stuff, and have written only one module so far in my 8 years with perl. But I've used a good few modules and OO bits from CPAN!

        ...roboticus