Xref: utzoo comp.lang.perl:5198 comp.unix.sysv386:7752 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!ucsd!nosc!humu!pegasus!pinhead!todd From: todd@pinhead.pegasus.com (Todd Ogasawara) Newsgroups: comp.lang.perl,comp.unix.sysv386 Subject: Perl unpack/tacct file Keywords: pack, unpack, tacct files Message-ID: <1991May04.185409.24228@pinhead.pegasus.com> Date: 4 May 91 18:54:09 GMT Organization: Hawaii Medical Service Association Lines: 51 I just started using Perl a few weeks ago and have run into a problem when trying to use unpack to look at 'tacct' type accounting files on an 386 box running Interactive UNIX 2.2 (UNIX System V/386 R3). I'm pretty sure I understand the structure of this file type since C programs I've written to read it work fine. The C structure of this file looks like this: #p = prime time, np = non-prime time #struct tacct { # unsigned short ta_uid; /* userid */ # char ta_name[8]; /* login name */ # float ta_cpu[2]; /* cum cpu time, p/np (mins) */ # float ta_kcore[2]; /* cum kcore-minutes, p/np */ # float ta_con[2]; /* cum connect time p/np, mins */ # float ta_du; /* cum disk usage */ # long ta_pc; /* count of processes */ # unsigned short ta_sc; /* count of login sessions */ # unsigned short ta_dc; /* count of disk samples */ # unsigned short ta_fee; /* fee for special services */ #}; Here's the perl program I've tried to use to read a tacct file with. (BTW, I'm using Perl 4.0 patch level 3). open(TACCT,"/usr/adm/acct/sum/tacct"); while(read(TACCT,$tacct,52)) { ($uid,$name,$cpuP,$cpuNP,$kcoreP,$kcoreNP,$conP,$conNP, $du,$pc,$sc,$dc,$fee) = unpack("S A8 f f f f f f f l S S S",$tacct); local($TCONNECT) = $conP + $conNP; printf "%4d %8s %7.2f %d %d\n", $uid, $name, $TCONNECT, $sc, $dc; } The $uid and $name variables contain what I expect it to. However, everything else that follows seems to be one off. I.e., The $dc variable should contain the number of disk samples but seems to contain the number of login sessions instead. The floating point values are all over the place. I know that I must be reading in the floating point variables incorrectly, but I don't know what it is that I'm doing wrong. BTW, I have the Wall & Schwartz "Programming Perl" book and have gone through the sections describing pack and unpack several times to try to understand what is going on here. Thanks for any help/hints anyone can offer. -- Todd Ogasawara ::: Hawaii Medical Service Association Internet ::: todd@pinhead.pegasus.com Telephone ::: (808) 536-9162 ext. 7