in reply to Looping

well these responses are all fine if your computer can tell time, but what if it can't? and what if the clock is wrong? you don't want to leave a critical application like this to chance.
open(MAIL, "|/usr/lib/sendmail timekeeper@superaccurateclock.com"); print MAIL <<END; From: Number Printer <numprint\@printnum.com> Subject: What Year is it? Please enter the year below and reply. Year: END close(MAIL); # ok, now watch our mail spool for the answer open(SPOOL, "tail -f /var/mail/spool/numprint |"); while(<SPOOL>) { if(/Year: (\d+)/) { $year = $1; last; } } close(SPOOL); # now we know for sure what year it is, we can use any # of the other suggestions to print the numbers

Replies are listed 'Best First'.
Re: Re: Looping
by samtregar (Abbot) on Jun 25, 2002 at 22:04 UTC
    How 1999. Why not be buzz-word compliant and use SOAP?

    use SOAP::Lite; $year = SOAP::Lite -> uri('http://www.yearknower.com/Year') -> proxy('http://soap.yearnknower.com/year.cgi') -> get_this_year -> result;

    -sam

    PS: Am I the only one that finds the OO calling style of the SOAP::Lite POD (shown above) bizarre? Is there any known precident or did the author invent it?

      Really good! I like your approach! And I think that robobunny got the point: if getting the right time is critical, you can't rely on yourself.

      Another solution would be to synchronize your server by means of the NTP protocol, which is the best way IMHO. I studied the principles of the protocol to implement a synchronization subnet for my job, and I was greatly surprised of how much statistical studies they put in; that makes NTP a higly-reliable protocol!

      Even if you don't want to invest a little to install a NTP server on your machine, you could take a look at the list of stratum 2 NTP servers and check if at least one of them offers the service by means of the daytime protocol too. To check, you can telnet to the tcp port 13 (i.e.: do a telnet host 13) and check if you get an output like:

      bronto@cooper:/tmp$ telnet myTimeServer 13 Trying 192.168.1.234... Connected to myTimeServer. Escape character is '^]'. Wed Jun 26 11:01:08 2002 Connection closed by foreign host.

      If so, you can get the current year using just Perl and Net::Telnet!

      Ciao!
      --bronto

      PS: if reading a document in italian language doesn't bother you, I can send a PDF doc I wrote about NTP and our synchronization subnet to anyone interested in. Just let me know!

      # Another Perl edition of a song:
      # The End, by The Beatles
      END {
        $you->take($love) eq $you->made($love) ;
      }