Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: structs? Message-ID: <1990Jul1.182421.22735@iwarp.intel.com> Date: 1 Jul 90 18:24:21 GMT References: <18249@fs2.NISC.SRI.COM> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 29 In-Reply-To: cwilson@NISC.SRI.COM (Chan Wilson) In article <18249@fs2.NISC.SRI.COM>, cwilson@NISC (Chan Wilson) writes: | I've got a data file that is of the format struct; that is, data is written out | with a C definition of thus: | | struct load { | time_t time; | ushort load; | }; [...] | Is it possible to read this file from perl, or would it be easier all around to | use a simple C program to read the data, then pipe it into perl? Naah. Do it all in Perl... open(F,"/where/its/at") || die "cannot open 'at': $!"; $buflen = length(pack("lS",0,0)); # how long is struct? while (read(F,$buf,$buflen) == $buflen) { ($time,$load) = unpack("lS",$buf); $load{$time} = $time; # maybe? or # push(@all,"$time $load"); # if you want a whole list } close(F); print grep($_=pack("c",hex($_)),unpack("A2"x 25,"4a75737420616e6f74686572205065726c206861636b65722c")) -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/