String interpolation in Scala 2.10 and newer (String variable substitution) alvin January 11, 2013 - 11:15am

Scala string FAQ: How do I embed variables in strings in Scala?

A lot of nice new features were added in Scala in version 2.10, but a simple feature that makes me happy is string interpolation. This lets Scala developers embed variables inside strings just like you can do in other languages like Perl, PHP, and Ruby -- but perhaps in an even more powerful way. (I say "perhaps" because I haven't used those other languages recently.)

How to embed data in your Perl program

Here's a sample Perl program that demonstrates how you can include (embed) data inside of your Perl program, right in there next to the source code.

This simple program takes the data after the special __END__ tag, and makes it available to your Perl source code.


while (<main::DATA>)
  print $_;

George Washington
Abraham Lincoln
John F. Kennedy

As you can see, you loop through the data with this line of code: