in reply to Re^2: [pack]little endian timestamp to decimal value
in thread [pack]little endian timestamp to decimal value

Great, I really couldn't find that out myself!

I actually tried running my script (it's fully Perl, not from commandline) also on a PowerPC. Obviously it returned another decimal value. I understand why, and it is really not a big issue. But I'm just wondering: Is it also possible to tell Perl how to treat a particular variable or value? Or let it run a function as being a in little-endian environment?
I actually thought that "<" would make Perl do that. But so far, no luck. Or am I doing something wrong?
Thanks again. You really helped me out again!

#!/usr/bin/perl -w use strict; my $hexvalue = $ARGV[0]; print unpack "L<", pack "H*", $hexvalue;
The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.

Replies are listed 'Best First'.
Re^4: [pack]little endian timestamp to decimal value
by ikegami (Patriarch) on Oct 26, 2010 at 23:43 UTC

    Obviously it returned another decimal value.

    For the same input, it should return the same on every machine, including your PowerPC.

    Or let it run a function as being a in little-endian environment?

    Since endianness only matters when you're talking about how something is stored and you can't access the buffers in which Perl stores its numbers, there's no way to be affected by endianness used. Your request makes no sense.

      absolutely...there's no way for a program to magically work out if a number is big or little endian. So the script somehow has to know that and use the appropriate kind of pack/unpack. or you could even just swap half the string around using string manipulation, before coalescing to decimal. either way it has to be known which way the endian goes. if these numbers are some well known numbers (say serial numbers for a computer product) then they usually already have some logic encoding to them, which could give you a clue. e.g. leftmost decimal 4 digits a valid vendor code in a known list, etc.
      the hardest line to type correctly is: stty erase ^H
        I'm not joking!
        I now tried it on 5 different machines with different Perl versions.

        1 PowerPC (PowerBook G4, running Gentoo Linux) Perl 5, version 12, subversion 2 (v5.12.2)
        1 PowerPC (PowerMac G4, running Gentoo Linux) Perl v5.8.8 built for powerpc-linux
        1 PowerPC G5 (PowerMac G5, running OS X 10.5) Perl v5.8.9 built for darwin-2level
        1 Dual Xeon (MacPro running OS X 10.6) Perl v5.8.9 built for darwin-2level
        1 Dual Xeon (Dell hardware Fedora Core 7) Perl v5.8.8 built for i386-linux-thread-multi


        And on all the PowerPCs I get as return: "3059448640"
        And on all the Intels I get as return: "1081826230"


        (Just to be clear: I tried running the code from the same share. And I typed it in all over.)
        #!/usr/bin/perl -w print unpack "L", pack "H*", "B65B7B4000";
        The great mistake is to anticipate the outcome of the engagement; Let nature take it's course, and your tools will strike at the right moment.