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

Re: Hex, Localtime and strings

by davido (Archbishop)
on Sep 26, 2012 at 17:18 UTC ( #995832=note: print w/replies, xml ) Need Help??

in reply to Hex, Localtime and strings

Because the first example uses a hex representation of an integer, and the second example uses a string of characters that happen to include a 0x and some stuff that looks (to a human) hex-ish (but not to Perl). Perl converts that string to a number following Perl's numerification of a string rules, which in this case results in a '0'.

use strict; use warnings; use diagnostics; my $daTime = "0x506143ca"; print scalar localtime $daTime, "\n";

...the output...

Argument "0x506143ca" isn't numeric in localtime at line 10 +(#1) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the me +ssage will identify which operator was so unfortunate. Wed Dec 31 16:00:00 1969

As for the "Wed Dec 31 16:00:00 1969": perl -E 'say localtime 0' will yield the same result.


Replies are listed 'Best First'.
Re^2: Hex, Localtime and strings
by theneil (Novice) on Sep 26, 2012 at 17:25 UTC
    Thank you guys! Worked like a charm! I'm slowly learning :)

      I know this is late, but I'll share what worked for me!

      $hexval = hex '51C07405'; print scalar(localtime($hexval));

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995832]
[davido]: sorry, typed that before you asked me to disable proc
[davido]: but you stumped me; don't know how to disable proc.
[tye]: I don't know if you can just dismount, but I thought so.
[davido]: yeah, umount -f isn't powerful enough.
[tye]: probably something in the init subsystem that does the mounting that you could disable and reboot.
davido needs to close laptop to board flight home from yapc.
[davido]: I'll look into it in a few hours probably.
[davido]: when i do get to that point I think I'll do it in a vm snapshot just in case. :)
[oiskuu]: tye, you were right: loginuid/sessionid are part of task struct if compiled with AUDITSYSCALL. I have some doubts if you should actually depend on that feature.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-06-23 20:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (555 votes). Check out past polls.