Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!charyb!dan From: dan@kfw.COM (Dan Mick) Newsgroups: comp.lang.perl Subject: Binary fixed-length records Message-ID: <1991Apr23.202307.2454@kfw.COM> Date: 23 Apr 91 20:23:07 GMT Reply-To: dan@kfw.com (Dan Mick) Organization: KFW Corporation, Newbury Park, CA Lines: 31 Often, I want to dump a file full of fixed-length records. The one way I've been using is #!/usr/local/bin/perl $stbuf_def="ccCCCCCCSSII"; # unpack codes for struct $streclen=20; # length of above in bytes $/ = 0777; # slurp in the whole file $_ = <>; # into $_ $inputlen = length($_); $offset = 0; while ($inputlen > 0) { $rec = substr($_, $offset, $streclen); $inputlen -= $streclen; $offset += $streclen; } ...but it strikes me that 1) the "slurp in whole file" will fail someday, and 2) the copy in the substr() can't be efficient. Anyone willing to take a crack? (I'm aware that the surrounding goo might not be as efficient as possible; what I'm mostly worried about are the two points above). If I could get the book, I would...