in reply to Variable Interpolation

my $string = "cheese"; my $need_to_interpolate = "smell my %s\n"; printf $need_to_interpolate, $string;

Replies are listed 'Best First'.
Re^2: Variable Interpolation
by ww (Archbishop) on Apr 29, 2005 at 20:19 UTC
    ok, i'll bite. certainly running "perl -d cheese.pl" didn't educate me much....
    debugger output: ... main::(cheese.pl:4): my $need_to_interpolate = "smell my %s\n"; DB<1> s main::(cheese.pl:5): printf $need_to_interpolate, $string; DB<1> x %s empty array ....

    How does the empty hash work, here?

      From perldoc -f sprintf:
      Perl's "sprintf" permits the following universally-known
      conversions:
         %%   a percent sign
         %c   a character with the given number
         %s   a string
         ...
      
        Anguished 'd'uh! /me is shamed, especially since I spent quite while puzzling about the use of printf, and still didn't stumble on the $s being conversion sted some undeclared and empty hash.

        Interesting warning there, in how I let -d output shape my train of thought.