When printing in Perl, you can drop a variable into a double quoted string ant it will be interpretter for you:
"--- $number ---"
If you want to perform an operation on the variable, though, it's not as easy - you have to come out of the double quoted string, do the calculation, then start another string:
"--- ",$number + 1," ---"
In Ruby, variable names do NOT start with a $ so you can't simply drop them in to your double quoted string. Instead, you can write #{expression} within the double quotes and that gives you ...
"--- #{number + 1} ---"
And that's fabulous - it gives you the ability to write any expresion you want, or just a simple variable, with a double quoted string and have the same simple syntax for both.
(written 2006-12-15 04:57:25)
Associated topics are indexed under
P205 - Perl - Initial String Handling [1860] Seven new intermediate Perl examples - (2008-10-30)
[1849] String matching in Perl with Regular Expressions - (2008-10-20)
[1608] Underlining in Perl and Python - the x and * operator in use - (2008-04-12)
[1195] Regular Express Primer - (2007-05-20)
[970] String duplication - x in Perl, * in Python and Ruby - (2006-12-07)
[324] The backtick operator in Python and Perl - (2005-05-25)
[254] x operator in Perl - (2005-03-22)
[31] Here documents - (2004-08-28)
R109 - Ruby - Strings and Regular Expressions [2623] Object Oriented Ruby - new examples - (2010-02-03)
[2621] Ruby collections and strings - some new examples - (2010-02-03)
[2614] Neatly formatting results into a table - (2010-02-01)
[2608] Search and replace in Ruby - Ruby Regular Expressions - (2010-01-31)
[2295] The dog is not in trouble - (2009-07-17)
[2293] Regular Expressions in Ruby - (2009-07-16)
[1891] Ruby to access web services - (2008-11-16)
[1887] Ruby Programming Course - Saturday and Sunday - (2008-11-16)
[1875] What are exceptions - Python based answer - (2008-11-08)
[1588] String interpretation in Ruby - (2008-03-21)
[1305] Regular expressions made easy - building from components - (2007-08-16)
[986] puts - opposite of chomp in Ruby - (2006-12-15)
Some other Articles
Adding a member to a Hash in RubyRuby - Totally TopicalMelksham QuizYou should think you're first in a hotel roomRuby v Perl - interpollating variablesEquality in Ruby - == eql? and equal?Cardinal numbers and magic numbersBlessing in Perl / Member variable in RubyNotes from the white board