At 11:22 AM 5/23/00 -0400, Dan Sugalski wrote:
>At 04:13 PM 5/23/00 +0100, Williams, Ivor wrote:
>>I'm trying to use the quad_to_date routine in VMS::Misc.
>>
>>I want to decode a DEC quadword date read off a file in binary as 8 bytes.
>>
>>I can verify using the VMS debugger on some C code that the date is valid,
>>but quad_to_date seems to be giving me garbage.
>>
>>Does it expect the 8 bytes as a string scalar? as a reference? Or pulling it
>>out via unpack as some flavour of integer?
>
>It expects an 8-byte string. Suck it in from the file as 8 plain bytes and pass it to
>quad_to_date and you should be OK.
Here's an example based on something I threw together when I first started
using these routines, HTH:
### start of quadtest.pl
use VMS::Misc qw/quad_to_date vms_date_to_unix_epoch/;
open (TIMFIL, 'TIMES.DAT') || die "Couldn't open file$!\n";
while ($line = <TIMFIL>)
{
($ascii_date,$raw_date) = unpack("A23a8", $line);
$date = &quad_to_date($raw_date);
$unix_date = gmtime(vms_date_to_unix_epoch($date));
print "$ascii_date ** $date ** $unix_date\n";
}
### end of quadtest.pl
Each record in TIMES.DAT contains a 23-byte ASCII date/time in VMS format,
followed by the same date in 8-byte binary format. substr() would probably
work just as well as unpack() but I was getting myself ready to pull dates
and other things out of a more complicated RMS record. If anyone wants the
data file to play with I can zip it up and send it off list. The output looks like
this:
4-JUL-1997 21:41:20.00 ** 04-JUL-1997 21:41:20.00 ** Sat Jul 5 02:41:20 1997
10-OCT-1998 19:58:24.00 ** 10-OCT-1998 19:58:24.00 ** Sun Oct 11 00:58:24 1998
16-JAN-2000 18:15:28.00 ** 16-JAN-2000 18:15:28.00 ** Sun Jan 16 23:15:28 2000
23-APR-2001 16:32:32.00 ** 23-APR-2001 16:32:32.00 ** Mon Apr 23 21:32:32 2001
30-JUL-2002 14:49:36.00 ** 30-JUL-2002 14:49:36.00 ** Tue Jul 30 19:49:36 2002
5-NOV-2003 13:06:40.00 ** 05-NOV-2003 13:06:40.00 ** Wed Nov 5 18:06:40 2003
_______________________________________________
Craig A. Berry
mailto:[EMAIL PROTECTED]