Path: utzoo!attcan!uunet!zephyr.ens.tek.com!tektronix!psueea!parsely!agora!markb From: markb@agora.UUCP (Mark Biggar) Newsgroups: comp.lang.perl Subject: Re: Variable variables Message-ID: <1894@agora.UUCP> Date: 21 Feb 90 07:31:42 GMT References: <29987@sparkyfs.istc.sri.com> Organization: Organization? You've got to be kidding! Lines: 29 In article <29987@sparkyfs.istc.sri.com> zwicky@sparkyfs.itstd.sri.com (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; > } Beside the various solutions using eval, you can also use the index concatenation feature of associative arrays $i = 1; foreach $device (@devices) { $DEV{$device,$i++} = something; } The elements of the list in the {} are concatenated to produce the actual index string used (as opposed to @DEV{$x,$y} which produces the list of elements selected.) This feature can be used to produce may useful data structures like sparce and ragged arrays. Constant separaters can easily be introduced to the list to allow parsing actual indecies out of the index returned from keys(). -- FROM SOMEONE THERE AT THE BEGINING Mark Biggar