Basic HTML version of Foils prepared March 30 97

Foil 11 Interpolation of Scalars into Strings (Chapter 2 of Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 We can use scalar variables in strings
  • $h= "World"; $hw= "Hello $h"; # sets $hw to "Hello World"
  • $h= "World"; $hw= "\UHello $h"; # sets $hw to "HELLO WORLD"
  • showing how \U and similarly \L operate on interpolated variables
2 As mentioned, there is NO interpolation for single quoted strings
3 There is also no recursion as illustrated below:
4 $fred= "You over there"; $x= '$fred'; $y= "Hey $x"; # sets $y as "Hey $fred" with no interpolation
5 Use \$ to ensure no interpolation where you need real $ character
  • $fred= "You over there"; $y= "Hey \$fred"; # sets $y as "Hey $fred" with no interpolation whereas:
  • $fred= "You over there"; $y= "Hey $fred"; # sets $y as "Hey You over there" with interpolation used
6 Use ${var} to remove ambiguity as in
  • $y= "Hey ${fred}followed by more characters";

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997