Re: FAQ 4.36 How can I expand variables in text strings?



In article <gcnmm5x06a.ln2@xxxxxxxxxxxxxxx>, Eric Pozharski
<whynot@xxxxxxxxxxxxxx> wrote:


C<ping-pong whatever> means a contents where participants attempt to
find as many ways to achieve something using some tools.

Well, that seems to have nothing to do with ping pong, a game of
hitting a ball back and forth over and over again.

Take a look at that part of answer (yes, it's taken out of context, but
that's what reader sees first):

my $foo = 'Fred';
my $bar = 'Barney';
$string = 'Say hello to $foo and $bar';

The question states C<How can I expand variables in text strings?>. The
unexpert reader (me?) doesn't get why C<q()> is used in place of
C<qq()>. The latter perfectly expands I<$foo> and I<$bar>.

If we used double quotes, it would interpolate the varaibles and we
wouldn't have a text string with placeholders that we need to expand,
and we wouldn't need the answer.


May be I've missed something again, but I failed to find in neither
question nor answer any notion that I<$foo> and I<$bar> are undefined at
compile time. BTW, the answer misses either discussion or redirection
why C<$string = eval { "Say hello to $foo and $bar"; };> is bad.

This isn't a relevant question for this topic. We're not talking about
interpolation of double quoted strings. We're talking about literal
strings---those don't do interpolation.

And the block eval does nothing for you, btw.
.



Relevant Pages

  • Re: Unexpected alteration of arrays content
    ... If I had a series of strings, ... I might consider array interpolation. ... true for natural languages, but also, to a lesser degree, for computer ... What readership a programmer expects may vary. ...
    (comp.lang.perl.misc)
  • Re: Coopting String interpolation
    ... > operation to all the strings that are interpolated. ... > interpolation works. ... All the ways I know for string composition ... Likely but also likely not accessible to pure Ruby code. ...
    (comp.lang.ruby)
  • Re: OOs best feature survey results
    ... Dynamic languages can be typed, ... BTW numerical is a type and string is another type. ... They don't map to my head, ... > Convert them to XML if you want to see strings. ...
    (comp.object)
  • Re: Coopting String interpolation
    ... > operation to all the strings that are interpolated. ... > interpolation works. ... All the ways I know for string composition ... Does ruby internally ...
    (comp.lang.ruby)
  • Re: Coopting String interpolation
    ... operation to all the strings that are interpolated. ... interpolation works. ... def initialize ... @vals = vals ...
    (comp.lang.ruby)