Perl - PowerPoint PPT Presentation

About This Presentation
Title:

Perl

Description:

Replace one set of characters with another, by position in list. tr /from/to/ #operates on ... How can you make a queue? Splicing Arrays. Similar to substring ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 10
Provided by: royl2
Learn more at: https://www.cse.fau.edu
Category:

less

Transcript and Presenter's Notes

Title: Perl


1
Perl
  • Hour 9More Functionsand Operators

2
Searching Strings
  • index string, substr, opt_start
  • index We all fall down, all
  • returns 3
  • index We all fall down, all, 4
  • returns 8
  • index(strat, z)
  • returns -1

3
Searching from right
  • rindex string, sub_str, opt_start
  • rindex We all fall down, all
  • returns 8

4
Substrings
  • substr string, start, opt_length
  • Use in expression to extract
  • Use on left of assignment to replace or insert
    (replace length 0 substring)
  • Negative start counts from right
  • Negative length ends at that count from right,
    strips last length characters

5
Substring Examples
  • a This is a test
  • substr a, 5 is a test
  • substr a, 5, 2 is
  • substr a, -9, -5 is a
  • substr(a, 7, 0) not This is not a test

6
Transliteration
  • Replace one set of characters with another, by
    position in list
  • tr /from/to/ operates on _
  • tr /A-Z/a-z/ Note range as lc
  • r tr/0-9/./ operates on r
  • Last to char repeated to match length
  • This form counts replacements in _
  • If second slot is empty, no replacement

7
Formatted Printing
  • printf as in C
  • sprintf too

8
Arrays as Stacks
  • Operations on arrays
  • push array, new_list on back
  • pop array returns last entry
  • shift array, new_list on front
  • unshift array returns first element
  • How can you make a queue?

9
Splicing Arrays
  • Similar to substring
  • splice array, o_offset, o_length, o_list
  • Returns removed part
  • Array is truncated to length
  • Removed items may be replaced
Write a Comment
User Comments (0)
About PowerShow.com