Urthas has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Consider the following code:Now consider this twist on the idea of a placeholder:$bar = "Hello %s world!\n"; if ($bar =~ m/(Hello)/) { $foo = lc $1; $foo =~ s/h/j/; printf $bar, $foo; # prints "Hello jello world!" }
Can I coerce Perl to DWIM? If so, how?$bar = "Hello $foo world!\n"; if ($bar =~ m/(Hello)/) { $foo = lc $1; $foo =~ s/h/j/; print "$foo\n"; # prints "jello" print $bar; # prints "Hello world!" }
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: placeholders without printf?
by ikegami (Patriarch) on Jan 23, 2010 at 03:29 UTC | |
by Urthas (Novice) on Jan 23, 2010 at 04:17 UTC | |
|
Re: placeholders without printf?
by Anonymous Monk on Jan 23, 2010 at 02:18 UTC | |
|
Re: placeholders without printf?
by graff (Chancellor) on Jan 23, 2010 at 16:38 UTC |