1 / 12

Introduction to Perl: P ractical e xtraction and r eport l anguage

Introduction to Perl: P ractical e xtraction and r eport l anguage. Origins Nature of Perl Characteristics of Perl Example. What is Perl?. Includes most powerful constructs from predecessor languages (sh, awk)

nancy
Download Presentation

Introduction to Perl: P ractical e xtraction and r eport l anguage

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Perl: Practical extraction and report language • Origins • Nature of Perl • Characteristics of Perl • Example

  2. What is Perl? • Includes most powerful constructs from predecessor languages (sh, awk) • From awk (text file processing utility)  Designed to write short programs to process text files, using pattern matching to produce reports of results • From UNIX sh, csh process creation and destruction

  3. What is Perl? • Added sockets  networking language to support communication with other processes and languages • Added modules and OOP Added constructs  expressive, flexible language

  4. History • Release 1.000 1987 designed by Larry Wall • Began as UNIX tool, but has spread • Popularity increased in 1990s • Portable systems programming language • Easily obtained and free • Useful for Common Gateway Interface (CGI) programming for WWW

  5. Language and Programs • Simple language – a beginner can write small useful programs • Complex language – has a richness and power to perform sophisticated tasks • Easy language to learn if you know C, sh or awk • Practical (easy to use, efficient, complete), but not beautiful • Be disciplined, follow standards  PERL programs will be readable

  6. Scripts vs Programs • Early OS/UNIX sh: • Small sequence of commands repeatedly typed  put into files and interpreted • Hence scripts • Perl evolved from shell languages • But Perl “scripts” are first compiled into intermediate language before interpreted • Hence Programs

  7. Central Characteristics • Implicit variables - defined by language implementation, not defined by user, but accessible • Variables are implicitly declared – type is inferred by compiler based on name syntax or context • Numbers are numbers - one numeric type, same as double (all literals and operations implicitly converted to this type) • Strings and numbers – implicit type conversions • No unnecessary limits – strings and arrays implicitly grow

  8. Central Characteristics • Scalar and list context • Array var when scalar expected  length of array • Scalar var when array expected  array of 1 element • Interchangeability of functions and operations • Ex. list operators in which op is followed by operands • Ex. Functions have () around operands, but can omit () • More than one way to do it • Simple techniques and more complex, elegant alternatives

  9. Getting Perl • www.activestate.com or My CD • Four directories needed: • doc – Perl doc (manpages) • src – source code files for Perl • ports – subdirectories and symbolic links for • implementations of Perl not supported by • standard distribution • scripts – collection of example Perl programs

  10. Other tools • Editor – NTEmacs free • www.cs.washington.edu/hones/voelker/ntemacs • Debugger – see ActiveState debugger

  11. Example Program To see listing of environment variables on your computer available to the program #!/usr/local/bin/perl foreach $key (keys (%ENV)) { print qq | The value of $key is ENV{"$key"}\n|; }

  12. Running Example Program • Save as with .pl extension • At command prompt type filename.pl • For verbose warnings type perl –w filename.pl • To run with debugger perl –d filename.pl

More Related