Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Time::Local has a function called timelocal (surprise) that converts information like that returned from localtime back into epoch seconds (like that returned from time). Consider this:

# get the epoch seconds for 8:00am the following day # NOTE if it's after midnight this doesn't work but # should be trivial to fix my $now = time(); my ($mday, $mon, $year) = (localtime($now))[3,4,5]; my $then = timelocal(0, 0, 8, $mday + 1, $mon, $year); my $difference = $then - $now; sleep($difference);

That should sleep until 8am the following day, but if you start that after midnight and before 8am, it won't work quite right. A little logic can fix that (add 1 to $mday unless the current hour is less than 8). Also it gets even more complicated if it's the last day of the month. That will break this completely and requires a lot more work to check for. And what if it's the last day of the year too? You'll need to check for that. Ok, so you set all that up too, but it's Februrary 28th on a leap year. Oops broke again.

In other words, it ain't easy. Maybe you should use Date::Calc.

Update I thought of something that might work also that doesn't involve these kinds of calculations. Sleep for 1 second until it's 8am, perhaps like so:

sleep(1) until ((localtime)[2] == 8); # it's now 8:00am.. do your thing.

Just an idea.

local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }


In reply to Re: How long 'tween now and then? by reptile
in thread How long 'tween now and then? by myocom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found