home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7474 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.7 KB  |  43 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!asuvax!ncar!mimbres.cs.unm.edu!constellation!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: unpack and shift idiom?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Dec17.001810.4070@news.eng.convex.com>
  8. Date: Thu, 17 Dec 1992 00:18:10 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <1992Dec16.180058.15351@bcars6a8.bnr.ca>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 25
  17.  
  18. From the keyboard of jsparkes@bcars68a.bnr.ca (Jeff Sparkes):
  19. :I'm reading binary data from a network stream.  I've accumulated the data in
  20. :a variable called $data, and am taking it apart in chunks.  The code
  21. :looks like:
  22. :    @output = unpack("L4S6", $data);
  23. :    $data = substr($data, 28);
  24. :    @names = unpack("A20", $data);
  25. :    ???
  26. :
  27. :I'm concerned by the need to use a constant as the arg to substr, especially
  28. :since I calculated it wrong the first time, and it took me a while to find.
  29. :This gets especially hairy when I pull strings out of the data stream, since
  30. :I don't know how many bytes to skip after unpacking A strings because some
  31. :stripping occurs.
  32. :
  33. :Please tell me I'm missing something!
  34.  
  35. You might try using c2ph to generate all the constants for you.
  36.  
  37. --tom
  38. -- 
  39.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  40.  
  41.  
  42.     The steady state of disks is full.  --Ken Thompson
  43.