First, you have a typo in your hex string: '00000034000031b110191403b8811bb1366e4' (the highlighted 1).
Second, if you run this on AIX (as I figure from the presence of "AIX" in the shebang path),
you most likely don't want the reverse stuff anyway, as AIX typically
runs on big-endian hardware, which already matches the binary format of your numbers...
In other words, on AIX, this should work (actually it does — tried it):
my $raw = pack "H*", '00000034000031b10191403b8811bb1366e4';
print "$_\n" for unpack 'NNCCd', $raw;
| [reply] [d/l] [select] |
Thanks so much - it work's great! One other question: what would be the best way to assign each value to a variable name? Again, thanks for your help - I'm definitely sold on PERL even though I'm a novice.
| [reply] |
my ($long1, $long2, $byte1, $byte2, $double) = unpack 'NNCCd', $raw;
(of course, choose names as you see fit...)
| [reply] [d/l] |
| [reply] |
I entered your code into a file with the PERL load module
Hm. I'm afraid I have no idea what that means? What is the "Perl load module"?
Perhaps you could cut & paste the terminal session to show what you did?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
This is what I'd like to be able to do but when I entered your code into a file with the PERL load module I didn't get anything like your output - I did get a huge floating point number! ..any suggestions - I am new at PERL as if you didn't already guess... Here's my file: #!/fs/COTS/gnu/bin/AIX/perl $raw = pack 'H*", '00000034000031b110191403b8811bb1366e4'; print for reverse unpack 'dCCVV', reverse $raw ; ..when I run this (simply type "test.pl") I get : 1331232565922520241.709119561536
| [reply] |
<code>
## Your code goes here
</code>
Your example will then display as: #!/fs/COTS/gnu/bin/AIX/perl
$raw = pack 'H*', '00000034000031b110191403b8811bb1366e4';
print for reverse unpack 'dCCVV', reverse $raw
Now, the reason you are not getting the same results is because no linefeeds are being produced, so all the numbers are being abutted. There are three ways to fix that problem.
- Append the newline character to the end of each thing printed:
#!/fs/COTS/gnu/bin/AIX/perl
$raw = pack 'H*', '00000034000031b110191403b8811bb1366e4';
print $_, "\n" for reverse unpack 'dCCVV', reverse $raw
- Add -l to the shebang line: (This is what I did.)
#!/fs/COTS/gnu/bin/AIX/perl -l
$raw = pack 'H*', '00000034000031b110191403b8811bb1366e4';
print for reverse unpack 'dCCVV', reverse $raw
- If you are using perl 5.10, then use say instead of print:
#!/fs/COTS/gnu/bin/AIX/perl
$raw = pack 'H*', '00000034000031b110191403b8811bb1366e4';
say for reverse unpack 'dCCVV', reverse $raw
BTW: Stupid as it is, some people will get upset with you if you continue to write "PERL". You should use 'Perl' or 'perl' (the first to indicate the language, the second to indicate the interpreter (load module)) in order to avoid that.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |