The time string can't be 32 bytes. VMS times are quadwords, 64 bit quantites. (Well, 63 bits, since negative times are deltas, but that's a separate issue) The data record format posted in the original node shows it as an 8 byte quantity and if it's in VMS format already, just snag the first eight bytes from the string an throw it in.

Regardless, as I said before, the code you've posted is wrong. (Which is a separate issue) You can't just go throwing a space between the two variables, nor can you just throw them together and hope for the best when a sub is going to decode the data, especially if it's binary data.. Won't work. The subroutine as written takes a single 64 bit quantity encoded as a VMS quadword time, so if that isn't what you have, you'll have problems. The code you wrote there definitely won't do it.

Given the original format, just read in the record and pass it to the subroutine, and it should work fine. If you don't want to do that, then:

$unix_time = quad_to_epoch(substr($record, 0, 8));
will.

In reply to Re: Re: Re: Re: Re: Re: Unpack for VMS binary files by Elian
in thread Unpack for VMS binary files by maderman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.