home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4915 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!network.ucsd.edu!nic!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: *Another* embarrassingly simple question
  5. Message-ID: <1992Jul23.190259.9652@netlabs.com>
  6. Date: 23 Jul 92 19:02:59 GMT
  7. References: <21982@venera.isi.edu>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 39
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <21982@venera.isi.edu> sondeen@isi.edu (Jeff Sondeen) writes:
  14. : By the way, I found some type of problem tring to use vec's.
  15. :     #! /local/bin/perl
  16. :     
  17. :     $num = 5;
  18. :     for $bits (1..20) {
  19. :         vec($numv, 0, $bits) = $num;
  20. :         @num = reverse(split(//,unpack("b$bits", $numv)));
  21. :         $line = join('',@num);
  22. :         print "$line\n";
  23. :     }
  24. : gives:
  25. : 1
  26. : 01
  27. : 101
  28. : 0101
  29. : 00101
  30. : 000101
  31. : 0000101
  32. : 00000101
  33. : 000000101
  34. : 0000000101
  35. : 00000000101
  36. : 000000000101
  37. : 0000000000101
  38. : 00000000000101
  39. : 000000000000101
  40. : 0000010100000000    ## what happend here????
  41. : 00000010100000000
  42. : 000000010100000000
  43. : 0000000010100000000
  44. : 00000000010100000000
  45.  
  46. vec() is only intended to work with $bits of 1, 2, 4, 8, 16, or 32.
  47.  
  48. Larry
  49.