Re: Class variable interpolation



August Karlstrom wrote:
Rik Wasmus wrote:
On Tue, 28 Oct 2008 01:58:40 +0100, August Karlstrom <fusionfile@xxxxxxxxx> wrote:

Hi,

Does anyone know the correct syntax to interpolate a class variable, $x say, inside a string? I tried

"{self::$x}"

but it produces the string

{self::x}

Here it will produce '{self::}', and a notice $x isn't set.
AFAIK, with static variables, one has the same 'problem' as with constants: no interpolation possible,

If that is the case it was probably overlooked by the language developers. I see no reason why static variables could not be interpolated with the syntax above.

just use temporary variables or concatenation.

Right, but it is kind of clumsy.


Using sprintf() and its ilk is also viable, and, IMO, can be easier on the eyes than relying on variable interpolation, anyway.

August

--
Curtis
$eMail = str_replace('sig.invalid', 'gmail.com', $from);
.



Relevant Pages

  • Re: Metacharacter problem in regexp
    ... wrong with regular expressions in Perl 5 and how are they going to look ... interpolation you've asked about and the klunky workaround I've sent ... any piece of program is a string. ... string as a regular expression. ...
    (perl.beginners)
  • Re: Expression Interpolation from input "template string"?
    ... Peter Fitzgibbons wrote: ... >>> What I don't know is how to get the interpolation to ... it's assuming that the stored string doesn't contain any}'s in it. ... probably some other templating code out there, ...
    (comp.lang.ruby)
  • Re: Optimization in PERL
    ... use single quotes rather than doubles. ... Print 'I am a static string I don't want to get interpolated'; ... is no interpolation going on, and you certainly won't measure any ... the compile time for large strings (but as you point out, ...
    (perl.beginners)
  • Re: what i am doing wrong here .. getting LDAP_STRONG_AUTH_NOT_SUPPORTED
    ... > string you evidently want interpolated. ... Interpolation does not occur in ... > of your lConnect routine to see if it failed or not. ... (NOTE without SASL) ...
    (comp.lang.perl.misc)
  • Re: double quotes vs. single quotes (was Re: hash as argument)
    ... :) Tom Christiansen say that they always use double quotes... ... :) Double quotes without interpolation or backslash escapes tricks ... :) that string than is necessary. ... nor do I think 'single quoted string'. ...
    (comp.lang.perl.misc)