home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / perl / 7650 < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.2 KB  |  55 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!gatech!psuvax1!atlantis.psu.edu!barr
  3. From: barr@pop.psu.edu (David Barr)
  4. Subject: Perl bug regarding ($foo,@bar)=&func();
  5. Message-ID: <u==1Hzt0ub@atlantis.psu.edu>
  6. Sender: news@atlantis.psu.edu (Usenet)
  7. Organization: Penn State Population Research Institute
  8. Date: Sat, 02 Jan 93 20:55:26 GMT
  9. Lines: 44
  10.  
  11. $RCSfile: perl.c,v $$Revision: 4.0.1.7 $$Date: 92/06/08 14:50:39 $
  12. Patch level: 35
  13.  
  14. In the following code, case 1 will work, while case 2 will seg fault.
  15. (Thanks to Bill Fenner for writing this sample code based on one of my
  16. messes)
  17.  
  18. Is there a fix for this?
  19.  
  20. #!/usr/bin/perl
  21. #
  22.  
  23. &recurse(1);
  24.  
  25. sub recurse {
  26.     local($level)=@_;
  27.     local(@foo);
  28.  
  29.     print "Level $level...\n";
  30. #
  31. # Case 1 works.
  32. #    @foo=&getstuf($level);        # case 1
  33. #    $junk=shift(@foo);        #
  34. #
  35. # Case 2 seg faults when we go to recurse
  36.     ($junk,@foo)=&getstuf($level);    # case 2
  37. #
  38.     print join(" ",@foo),"\n";
  39.     foreach $i (@foo) {
  40.         print "About to call recurse($i)...\n";
  41.         &recurse($i);
  42.     }
  43. }
  44.  
  45. sub getstuf {
  46.     local($level)=@_;
  47.  
  48.     ("junk",($level > 5) ? () : (($level+1) x $level));
  49. }
  50.  
  51. --Dave
  52. -- 
  53. System Administrator, Population Research Institute    barr@pop.psu.edu
  54. #define ENOTTY          25              /* Not a typewriter */
  55.