Perl under the Hood - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Perl under the Hood

Description:

The University of North Carolina at Chapel Hill. 2. How ... to its symbol tables. Variables are either global or lexical. Names can refer to data and nondata ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 7
Provided by: felixherna
Category:
Tags: hood | nondata | perl | under

less

Transcript and Presenter's Notes

Title: Perl under the Hood


1
Perl under the Hood
The University of North Carolina at Chapel Hill
  • COMP 144 Programming Language Concepts
  • Spring 2003

David Stotts Feb 4
2
How does the Interpreter work?
  • Perl gives program access to its symbol tables
  • Variables are either global or lexical
  • Names can refer to data and nondata
  • spud, _at_spud, spud spud, spud (filehandle), all
    are the name spud used for different things
  • Symbol table is a hash table with separate areas
    for each kind of thing
  • A typeglob is a multi-tail pointer pile for
    each name in the hash table

3
Symbol table structure
Typeglob ( spud )
Scalar value ( spud )
spud
List value (array) (_at_spud)
arf
Hash value (spud)
Code value (spud)
foo3
Filehandle (spud)
Format (ignore this)
Typeglob ( arf )
Symbol table (hashed)
Typeglob ( foo3 )
4
Eval the Interpreter itself
  • A Perl script can directly run a copy of its own
    interpreter
  • One way theeval function
  • while (line ltgt)
  • str . line slarp in all lines and
    concat them
  • eval str now run the interpreter on it
  • str c a b
  • a 10 b 15
  • eval str treats value of str as
    code and executes it
  • print c\n prints 25

5
Interpreter (cont.)
  • Check this out
  • while (defined(s ltgt))
  • result eval s
  • if ( _at_ )
  • print Invalid input string\n s
  • else
  • print result, \n
  • Interactive Perl interpreter voila

6
References
  • S. Srinivasan, Advanced Perl Programming,
    OReilly, 1997
Write a Comment
User Comments (0)
About PowerShow.com