Interpolation - PowerPoint PPT Presentation

About This Presentation
Title:

Interpolation

Description:

Interpolation = replacing symbol/variable with its meaning within a string. Two kinds of interpolation variable and backslash ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 7
Provided by: csr8
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Interpolation


1
Interpolation
  • Variable Interpolation,
  • Backslash Interpolation

2
Interpolation
  • Sometimes called substitution
  • In Perl, Substitution means something else
  • Interpolation replacing symbol/variable with
    its meaning within a string
  • Two kinds of interpolation variable and
    backslash
  • Done only in double-quoted strings, not
    single-quoted strings.

3
Backslash interpolation
  • aka character interpolation, character escapes,
    escape sequences.
  • When any of these sequences are found inside a
    double quoted string, theyre interpolated
  • Listed on page 61 of Prog. Perl.
  • Most common \n, \t

4
Translation Escapes
  • pg 61, table 2-2 of Prog.Perl
  • \u next character is uppercase
  • \l next character is lowercase
  • \U all characters until \E are uppercase
  • \L all characters until \E are lowercase
  • \Q all characters until \E are backslashed
  • \E end \U, \L, or \Q

5
Variable Interpolation
  • variables found within are interpolated.
  • strings are NOT searched for interpolation
  • foo hello
  • bar foo world
  • bar gets value hello world
  • bar2 foo world
  • bar2 gets value foo world

6
What can interpolate?
  • Scalars, arrays, slices of arrays, slices of hash
  • NOT entire hashes
  • Arrays (and slices) will print out each member of
    array separated by a space
  • ex _at_array (1, 3, 5, 7)
  • print The first 4 odd numbers are _at_array\n
  • outputs The first 4 odd numbers are 1 3 5 7
  • Change separation sequence via variable
Write a Comment
User Comments (0)
About PowerShow.com