Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!apple!oliveb!orc!mipos3!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Variable variables Message-ID: <1990Feb15.195712.6845@iwarp.intel.com> Date: 15 Feb 90 19:57:12 GMT References: <29987@sparkyfs.istc.sri.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 36 In-Reply-To: zwicky@sparkyfs.itstd.sri.com (Elizabeth Zwicky) In article <29987@sparkyfs.istc.sri.com>, zwicky@sparkyfs (Elizabeth Zwicky) writes: | I have an array, @devices, consisting of a list of device names read | from the command line. For each of those devices, I need an array | consisting of the machines supposed to be backed up to that device. | What I would like to do is something like this, were this grammatical: | | foreach $device (@devices){ | @$device = something; | } Pretty darn close for guessing. Try: for $device (@devices) { eval '@' . $device . ' = something'; } But, how are you going to get the values back out? I've done similar stuff, and the fastest ends up looking like: for $device (@devices) { $dev{$device} = "some space separated values"; } and then when I'm working on device foo: @values = split(/ /,$dev{'foo'}); to get the array back. Use whatever delimiter doesn't appear in your values. Just another Perl hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/