home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7041 < prev    next >
Encoding:
Text File  |  1992-11-18  |  1.5 KB  |  50 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!fmrco!fmrco!asherman
  3. From: asherman@fmrco.com (Aaron Sherman)
  4. Subject: Solution to the "@x{...} = (1) x 1000" problem
  5. Message-ID: <ASHERMAN.92Nov18114024@piranha.fmrco.com>
  6. Sender: news@fmrco.uucp
  7. Reply-To: asherman@fmrco.COM
  8. Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
  9. Date: Wed, 18 Nov 1992 16:40:24 GMT
  10. Lines: 38
  11.  
  12.  
  13. I think that I have a solution to the problem of wanting to fill an
  14. array with a uniform initial value, ie:
  15.  
  16.     @x{grep(</usr/local[0-9]/*>)} = (1) x 1000
  17.  
  18. The method above will work (as long as there are 1000 or less
  19. /usr/local<n>/* files, but memory is wasted, and an assumption has
  20. to be made. My solution would be this:
  21.  
  22.     @x{...} = replicate(1);
  23.  
  24. "replicate" is a function that takes ONE argument, and creates a dummy
  25. array which actually has no length. No matter what element of the
  26. array you look up, you get the scalar value that is passed to
  27. replicate.
  28.  
  29. The problem is that this needs a new way of dealing with assignment.
  30. For instance:
  31.  
  32.     @x = replicate(1);
  33.  
  34. would set $#x to what? I would suggest that it assign as many elements
  35. as the array currently contains, or one by default. This way the
  36. initial purpose is preserved.
  37.  
  38. Can this be done? Easily? Any chance of seeing it in perl5?
  39.  
  40. Thanks.
  41.  
  42.  
  43.             -AJS
  44.  
  45. --
  46. --------
  47. Disclaimer: I am solely responsible for the content of this message.
  48. The views expressed here may not be the views of I-Kinetics, Fidelity,
  49. any of the Fidelity-owned corporations or my mother.
  50.