home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7530 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  3.8 KB

  1. Path: sparky!uunet!usc!cs.utexas.edu!torn!nott!bnrgate!bcars664!leibniz!walt
  2. From: walt@bcarh1d7.bnr.ca (Walt Sullivan)
  3. Newsgroups: comp.lang.perl
  4. Subject: unpack() limitation/bug?
  5. Message-ID: <WALT.92Dec18165612@bcarh1d7.bnr.ca>
  6. Date: 18 Dec 92 21:56:12 GMT
  7. Sender: news@bcars664.bnr.ca
  8. Distribution: world
  9. Organization: Bell-Northern Research, Ottawa, Canada
  10. Lines: 99
  11.  
  12. It seems that I can't unpack() more than 9 fields. Can this be true? 
  13. Here's the script that shows the problem:
  14.  
  15. ------------------------------ Cut here ------------------------------
  16. #!/usr/bin/perl
  17. @templates = (" @0 A5"," @6 A15"," @22 A4"," @27 A12"," @40 A2"," @43 A2"," @46 A8"," @55 A6"," @62 A15"," @78 A12"," @91 A5"," @97 A8"," @106 A15"," @122 A12");
  18. $line = "AAAAA BBBBBBBB        CCCC DDDDDDDD     EE FF GGGGGGGG HHHH   IIIIIIIII       JJJJJJJJJJJJ                KKKKKKKK        LLLLL          ";
  19. print "Perl version $]\n";
  20. print "line length = ", length($line),"\n";
  21. print "line=/$line/\n";
  22. foreach $template ( @templates ) {
  23.   print "$template produces /", unpack($template, $line), "/\n";
  24. }
  25. print "See, each one works. Now we'll use several\n\n";
  26.  
  27. $grow = "";
  28. foreach $template( @templates) {
  29.   $grow .= $template;
  30.   print "template=/",$grow,"/\nunpack  =/";
  31.   (@result) = unpack($grow, $line);
  32.   print join("/",@result),"/\n";
  33. }
  34. exit(0);
  35. ------------------------------ Cut here ------------------------------
  36.  
  37. And here's what I get, using Perl 4.0, pl 19 on HP-UX 8.0 on a 9000/360.
  38. I get the same result using Perl 4.0 pl 19 on a Sun Sparc I, SunOS 4.1.1:
  39.  
  40. ------------------------------ Cut here ------------------------------
  41. Script started on Fri Dec 18 16:27:00 1992
  42. bcarh1d7-61> uname -a
  43. HP-UX bcarh1d7 B.08.00 A 9000/360 080009016376
  44. bcarh1d7-62> perl -v
  45.  
  46. This is perl, version 4.0
  47.  
  48. $RCSfile: perl.c,v $$Revision: 4.0.1.6 $$Date: 91/11/11 16:38:45 $
  49. Patch level: 19
  50.  
  51. Copyright (c) 1989, 1990, 1991, Larry Wall
  52.  
  53. Perl may be copied only under the terms of either the Artistic License or the
  54. GNU General Public License, which may be found in the Perl 4.0 source kit.
  55. bcarh1d7-63> perl perl.bug
  56. Perl version $RCSfile: perl.c,v $$Revision: 4.0.1.6 $$Date: 91/11/11 16:38:45 $
  57. Patch level: 19
  58.  
  59. line length = 137
  60. line=/AAAAA BBBBBBBB        CCCC DDDDDDDD     EE FF GGGGGGGG HHHH   IIIIIIIII       JJJJJJJJJJJJ                KKKKKKKK        LLLLL          /
  61.  @0 A5 produces /AAAAA/
  62.  @6 A15 produces /BBBBBBBB/
  63.  @22 A4 produces /CCCC/
  64.  @27 A12 produces /DDDDDDDD/
  65.  @40 A2 produces /EE/
  66.  @43 A2 produces /FF/
  67.  @46 A8 produces /GGGGGGGG/
  68.  @55 A6 produces /HHHH/
  69.  @62 A15 produces /IIIIIIIII/
  70.  @78 A12 produces /JJJJJJJJJJJJ/
  71.  @91 A5 produces //
  72.  @97 A8 produces //
  73.  @106 A15 produces /KKKKKKKK/
  74.  @122 A12 produces /LLLLL/
  75. See, each one works. Now we'll use several
  76.  
  77. template=/ @0 A5/
  78. unpack  =/AAAAA/
  79. template=/ @0 A5 @6 A15/
  80. unpack  =/AAAAA/BBBBBBBB/
  81. template=/ @0 A5 @6 A15 @22 A4/
  82. unpack  =/AAAAA/BBBBBBBB/CCCC/
  83. template=/ @0 A5 @6 A15 @22 A4 @27 A12/
  84. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/
  85. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2/
  86. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/EE/
  87. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2 @43 A2/
  88. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/EE/FF/
  89. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2 @43 A2 @46 A8/
  90. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/EE/FF/GGGGGGGG/
  91. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2 @43 A2 @46 A8 @55 A6/
  92. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/EE/FF/GGGGGGGG/HHHH/
  93. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2 @43 A2 @46 A8 @55 A6 @62 A15/
  94. unpack  =/AAAAA/BBBBBBBB/CCCC/DDDDDDDD/EE/FF/GGGGGGGG/HHHH/IIIIIIIII/
  95. template=/ @0 A5 @6 A15 @22 A4 @27 A12 @40 A2 @43 A2 @46 A8 @55 A6 @62 A15 @78 A12/
  96. unpack  =/@ outside of string at perl.bug line 16.
  97. bcarh1d7-64> 
  98. script done on Fri Dec 18 16:27:21 1992
  99. ------------------------------ Cut here ------------------------------
  100.  
  101. Help!
  102.  
  103. Walt
  104.  
  105.  
  106. --
  107. Walt Sullivan
  108. INTERNET: walt@bnr.ca (work)
  109. UUCP: walt@orbit.ocunix.on.ca (home)
  110. FIDO: 1:163/109.4
  111.