Basic HTML version of Foils prepared Sept 20 97

Foil 13 Interpolation of Scalars into Strings

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


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
Remember, there is NO interpolation for single-quoted strings!
There is also no recursion as illustrated below:
$fred= "You over there"; $x= '$fred'; $y= "Hey $x"; # sets $y as 'Hey $fred' with no interpolation
Use \$ to ensure no interpolation where you need literal $ 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
Use ${var} to remove ambiguity as in
  • $y= "Hey ${fred}followed by more characters";



© 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 Sun Sep 21 1997