• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Python & Perl: Lecture 27

Python & Perl: Lecture 27






Total Views
Views on SlideShare
Embed Views



16 Embeds 410

http://vkedco.blogspot.com 284
http://www.vkedco.blogspot.com 88
http://vkedco.blogspot.in 11
http://vkedco.blogspot.fr 4
http://vkedco.blogspot.nl 3
http://vkedco.blogspot.pt 3
http://vkedco.blogspot.de 3
http://vkedco.blogspot.com.es 3
http://www.vkedco.blogspot.in 3
http://vkedco.blogspot.ca 2
http://www.vkedco.blogspot.com.es 1
http://vkedco.blogspot.kr 1
http://vkedco.blogspot.co.uk 1
http://vkedco.blogspot.mx 1
http://vkedco.blogspot.co.il 1
http://vkedco.blogspot.ru 1


Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Python & Perl: Lecture 27 Python & Perl: Lecture 27 Presentation Transcript

    • Python & Perl Lecture 27 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
    • Outline ● Packages & Modules ● Some Theoretical Background on Regular Expressionswww.youtube.com/vkedco www.vkedco.blogspot.com
    • Packages & Moduleswww.youtube.com/vkedco www.vkedco.blogspot.com
    • Packages ● One can think of a package as a set of identifiers (e.g., variable and subroutine names) ● In C++, packages are called namespaces ● A package has its own symbol table that stores its variables and subroutine names ● By default, Perls variable and subroutine names are stored in the main packagewww.youtube.com/vkedco www.vkedco.blogspot.com
    • Packages & Variables ● Lexical variables (declared with my) are not stored in the packages symbol table ● Each block of code where lexical variables are defined stores them in a temporary table known as scratchpad ● Symbol tables are typically implemented as hasheswww.youtube.com/vkedco www.vkedco.blogspot.com
    • Packages & Variables ● Keys are variable/subroutine names and values are memory locations where they are stored ● One package cannot have the same identifier referring to different memory locations ● When the same identifier refers to two (or more) memory locations, there is a symbol clashwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Packages & Variables ● You can define the package of a specific identifier explicitly by prefixing it with the name of the package ● Examples: $main::x = 5; ## $x is defined in main @main::z = (1 .. 5); ## @z is defined in main @vladimir::z = (a .. e); ## @ z is defined in vladimirwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Example package_vars.plwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Perl Modules ● One can think of a Perl module as a separate software component ● Perl modules have .pm extensions ● A module is a set of packages plus some possible set of conventions on how those packages are used ● A collection of modules is called a distribution ● The site www.cpan.org offers an impressive list of available Perl modules and distributionswww.youtube.com/vkedco www.vkedco.blogspot.com
    • Special Variable @INC ● When a module or a file needs another module at run time, it must require the module ● The statement require ModuleName; makes Perl look for the module and add its contents to the running program ● Perl first looks for the package in the current directory; if the package is not found, each directory specified in the array @INC is checked in sequencewww.youtube.com/vkedco www.vkedco.blogspot.com
    • Example show_inc_array.plwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Inter-Package Subroutine Access ● A subroutine in package A can call a subroutine in package B ● Example: a subroutine in A calls a subroutine g in B as follows: B::g() ● Example: a subroutine in B calls a subroutine g in A as follows: A::g()www.youtube.com/vkedco www.vkedco.blogspot.com
    • Example SamplePack.pm sample_pack_driver_01.plwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Variable Access ● Subroutines have access to globally scoped variables defined in other modules ● Subroutines do not have access to lexically scoped variables defined in other modules ● Globally scoped variables in other modules must be qualified with the name of the modules where they are definedwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Example SamplePack.pm sample_pack_driver_02.pl sample_pack_driver_03.pl sample_pack_driver_04.plwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Subroutine Identifier Export ● One package may export subroutines to other packages ● If A exports f and B has use A;, then B can use f without the package qualifier A:: ● If A does not export f and B has use A;, then B must use the package qualifier A::www.youtube.com/vkedco www.vkedco.blogspot.com
    • Example PackOne.pm PackTwo.pm two_pack_driver.plwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Some Theoretical Background on Regular Expressionswww.youtube.com/vkedco www.vkedco.blogspot.com
    • Formal Languages • A language is a set of strings over an alphabet • Σ* is the Kleene closure of Σ and denotes the set of all strings over Σ including ε • Examples: – If Σ = {a}, then Σ* = {a}* = {ε, a, aa, aaa, aaaa, …} – If Σ = {0,1}, then Σ* = {0,1}* is an infinite set that includes all strings of 0’s and 1’s and εwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Deterministic Finite Automata • A DFA can be informally defined as a directed graph whose nodes are states and whose edges are transitions on specific symbols • A DFA has a unique start state and a set (possibly empty) of final or accepting states • A DFA processes the input string one symbol at a time. When the last symbol is read, the DFA reaches a state which is either final or not. If the state is final, the DFA accepts (recognizes) the string. If the state is not final, the DFA rejects the stringwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Feedback Errors, comments, questions to vladimir dot kulyukin at gmail dot comwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Reading & References ● Dietel, Dietel, Nieto, McPhie. Perl How to Program, Prentice Hall ● James Lee. Beginning Perl, 2 nd Edition, APRESSwww.youtube.com/vkedco www.vkedco.blogspot.com