This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Finding either boot time or login time

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
different goals.

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[0])' /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
hibernation. :)

Mark J. Reed <>

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]