Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!frankland-river!pem From: pem@frankland-river.aaii.oz.au (Paul E. Maisano) Newsgroups: comp.lang.perl Subject: Re: Creating a reference to an array index Message-ID: <1366@frankland-river.aaii.oz.au> Date: 19 Mar 90 05:48:40 GMT References: <1361@frankland-river.aaii.oz.au> <1362@frankland-river.aaii.oz.au> Organization: Australian AI Institute Lines: 38 In article <1362@frankland-river.aaii.oz.au>, I (Paul E. Maisano) write: > For anyone interested &ref can be defined as follows: > sub ref { > local($tmp); > grep($tmp = *_, $_[0]); > $tmp; > } > This routine could be made more general by returning an array of > references for each argument. Ie. you could write, > local(*x, *y, *z) = &ref($x[1], $y[0], $z[2]); The generalized version is: sub ref { local(@stab); grep(push(@stab,*_),@_); # kludge to get at symtab entries wantarray ? @stab : $stab[0]; # contains the binary symtab data } > You could even set things up so that two arrays share elements!! Ignore that. As far as I can tell there is no way whatsoever in the current version of perl to make an array element reference something else. I agree that it's probably not of any real use anyway. The reason I think it is impossible, is that the only way you can make something reference another symbol in perl is to use the type globbing syntax. And you aren't allowed to do "*LVALUE = ..." only "*NAME = ...". In other words, you can't name an array element; only the array. BTW, I would also like to see gethostname (and some version of timelocal) in perl. [But I've already voted for these so it doesn't count, right!? :-] ------------------ Paul E. Maisano Australian Artificial Intelligence Institute 1 Grattan St. Carlton, Vic. 3053, Australia Ph: +613 663-7922 Fax: +613 663-7937 Email: pem@aaii.oz.au UUCP: {uunet,mcsun,ukc,nttlab}!munnari!aaii.oz.au!pem