This is the mail archive of the
mailing list for the Cygwin project.
Re: Finding either boot time or login time
- From: "Mark J. Reed" <markjreed at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 2 Feb 2009 15:27:59 -0500
- Subject: Re: Finding either boot time or login time
- References: <loom.20090130T125737email@example.com> <4982FB77.firstname.lastname@example.org> <loom.20090130T152913email@example.com> <188.8.131.52.1.20090130164221.01ec8dd0@localhost> <firstname.lastname@example.org> <loom.20090202T140523email@example.com> <firstname.lastname@example.org>
On Mon, Feb 2, 2009 at 9:11 AM, Ronald Fischer wrote:
> Would you mind explaining the ~~ trick?
Not at all, but I'll do so offlist. Perl-fu is not on-topic for Cygwin.
On Mon, Feb 2, 2009 at 9:34 AM, Jerry D. Hedden wrote:
> Clever tricks are interesting, but definitely are an obfuscation.
It's a one-liner; the goal is compactness/expressiveness, not
intentional obfuscation. Sure, in a standalone script (or larger
system) I would have used scalar() instead of ~~. I also would have
explicitly opened, read, and split the contents of /proc/uptime
instead of using the -a and -n options, and explicitly terminated the
output string with "\n" instead of using the -l option. In other
words, ~~ is a common Perl idiom, whose use is no more obfuscating
than that of those command-line options. Different methods for
On Mon, Feb 2, 2009 at 11:54 AM, Cooper, Karl (US SSA) wrote:
> I did try both of these one-liners on my
> Cygwin 1.7 setup, and the output differs (by one second). I thought
> that was interesting.
Rounding difference. Besides replacing my ~~ with scalar(), Jerry
added an int() call to truncate the value read from /proc/uptime - and
that change was more than cosmetic. Since the return value of time()
is only accurate to the nearest integer, my script would return
different values depending on how far into the current second you were
when running it; Jerry's should behave more consistently. Another
option is to correct in the other direction by using the Time::HiRes
module to cause the return value of time() to have millisecond
$ perl -MTime::HiRes=time -lane 'print ~~localtime(time - $F)' /proc/uptime
But it seems silly to worry about a one-second error on a call that is
apparently subject to much larger error due to the effect of
Mark J. Reed <email@example.com>
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html