Path: utzoo!attcan!uunet!aplcen!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: I ${$a} Message-ID: <9932@jpl-devvax.JPL.NASA.GOV> Date: 11 Oct 90 21:17:46 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 43 In article stef@zweig.sun (Stephane Payrard) writes: : : I would expect a expression like ${$a} to evaluate from : inside out: : It is not the case as demonstrated by the following : test. : : : % perl -e '$b=2;$a="b";print ${$a};' : : I would expect ${$a} to evaluate to 1 the following way: : : ${$a} -> ${"b"} -> $b -> 1 : : : What is the canonic way to write an expression which : behaves like I exprected (I guess it imply to use `eval'). : : This lead to RFE: : supporting this kind of multilevel evalation of string: : -If an expression contains the construct ${expression}, : this construct is evaluated and replaced by its value : before the string contained it is evaluated. Multi-level evaluation is one of the things that makes shell programming such a pain. I'm not gonna do that to Perl. You'll note "text`command`text" doesn't work either. I'd rather force you to make a few extra temporary variables than have people writing "Perl scripts out of hell". They're bad enough coming out of purgatory. In the ${...} construct, the {} characters only perform grouping and quoting. No evaluation of anything is implied other than a possible subscript, e.g. inside ${foo[$bar]} or ${foo{$bar}}. In particular, in ${$a}, the second $ is only allowed accidentally because ${$} must be allowed as a synonym for $$, so it doesn't check the first character to make sure it's alphanumeric like it does the rest of the characters. Thus, the way it currently stands, you can say ${^Afoo} (where ^A is a real control/a, but you can't say ${foo^A}. I wouldn't, of course, depend on this for anything if I were you, since it's undocumented and may change. In fact, once upon a time, *any* sequence of characters was allowed inside the {}, but it was tightened up some when we instituted ${foo[$bar]}. Larry