home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!fmrco!fmrco!asherman
- From: asherman@fmrco.com (Aaron Sherman)
- Subject: Solution to the "@x{...} = (1) x 1000" problem
- Message-ID: <ASHERMAN.92Nov18114024@piranha.fmrco.com>
- Sender: news@fmrco.uucp
- Reply-To: asherman@fmrco.COM
- Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
- Date: Wed, 18 Nov 1992 16:40:24 GMT
- Lines: 38
-
-
- I think that I have a solution to the problem of wanting to fill an
- array with a uniform initial value, ie:
-
- @x{grep(</usr/local[0-9]/*>)} = (1) x 1000
-
- The method above will work (as long as there are 1000 or less
- /usr/local<n>/* files, but memory is wasted, and an assumption has
- to be made. My solution would be this:
-
- @x{...} = replicate(1);
-
- "replicate" is a function that takes ONE argument, and creates a dummy
- array which actually has no length. No matter what element of the
- array you look up, you get the scalar value that is passed to
- replicate.
-
- The problem is that this needs a new way of dealing with assignment.
- For instance:
-
- @x = replicate(1);
-
- would set $#x to what? I would suggest that it assign as many elements
- as the array currently contains, or one by default. This way the
- initial purpose is preserved.
-
- Can this be done? Easily? Any chance of seeing it in perl5?
-
- Thanks.
-
-
- -AJS
-
- --
- --------
- Disclaimer: I am solely responsible for the content of this message.
- The views expressed here may not be the views of I-Kinetics, Fidelity,
- any of the Fidelity-owned corporations or my mother.
-