UNCA CSCI 431 - Introduction to Scripting Languages and Perl Basics

Unformatted text preview:

Introduction to Scripting Languages and Perl BasicsOrigin of Scripting LanguagesHigh-Level Programming LanguagesHigher-level ProgrammingSlide 5Typing and ProductivityPerlCharacteristicsPerl can be simpleRunning a Perl programData TypesScalar TypesComparing strings and numbersContextSlide 15ArraysSlide 17Slide 18HashsI/O with PerlPerl I/OSlide 22Reading Assignment11Introduction to Scripting Introduction to Scripting Languages and Perl BasicsLanguages and Perl BasicsCSCI 431 Programming LanguagesCSCI 431 Programming LanguagesFall 2003Fall 2003A modification of slides developed by Felix A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill Hernandez-Campos at UNC Chapel Hill22Origin of Scripting LanguagesOrigin of Scripting Languages•Scripting languages originated as Scripting languages originated as job control job control languageslanguages–1960s: IBM System 360 had the Job Control Language1960s: IBM System 360 had the Job Control Language–ScriptsScripts used to control other programs used to control other programs»Launch compilation, executionLaunch compilation, execution»Check return codesCheck return codes•Scripting languages got increasingly more powerful Scripting languages got increasingly more powerful in the UNIX world in the early 1970’sin the UNIX world in the early 1970’s–Shell programming (sh, csh, ksh), AWK, SED, GREPShell programming (sh, csh, ksh), AWK, SED, GREP–ScriptsScripts used to combine used to combine componentscomponents»GluingGluing applications [Ousterhout, 97] applications [Ousterhout, 97]33High-Level Programming LanguagesHigh-Level Programming Languages•High-level programming languages replaced High-level programming languages replaced assembly languagesassembly languages–Benefits:Benefits:»The compiler hides unnecessary details, so these languages have a The compiler hides unnecessary details, so these languages have a higher level of abstraction, increasing productivityhigher level of abstraction, increasing productivity»They are They are strongly typedstrongly typed, , i.e. i.e. meaning of information is specified meaning of information is specified before its use, enabling substantial error checking at compile timebefore its use, enabling substantial error checking at compile time»They make programs more portableThey make programs more portable–HLPLs and ALs are both intended to write application HLPLs and ALs are both intended to write application from scratchfrom scratch–HLLs try to minimize the loss in performance with respect HLLs try to minimize the loss in performance with respect to ALsto ALs–E.g.E.g. PL/1, Pascal, C, C++, Java PL/1, Pascal, C, C++, Java44Higher-level ProgrammingHigher-level Programming•Scripting languages provide an even higher-level of Scripting languages provide an even higher-level of abstractionabstraction–The main goal is programming productivityThe main goal is programming productivity»Performance is a secondary considerationPerformance is a secondary consideration–Modern SL provide primitive operations with greater Modern SL provide primitive operations with greater functionalityfunctionality•Scripting languages are usually (almost always) Scripting languages are usually (almost always) interpretedinterpreted–Interpretation increases speed of developmentInterpretation increases speed of development»Immediate feedbackImmediate feedback–Compilation to an intermediate format is commonCompilation to an intermediate format is common55Higher-level ProgrammingHigher-level Programming•They are They are weakly typedweakly typed–I.e. I.e. Meaning of information is inferredMeaning of information is inferredLess error checking at compile-time Less error checking at compile-time »Run-time error checking is less efficient, but possibleRun-time error checking is less efficient, but possibleWeak typing increases speed of developmentWeak typing increases speed of development»More flexible interfacingMore flexible interfacing»Fewer lines of codeFewer lines of code•They are not usually appropriate forThey are not usually appropriate for–Efficient/low-level programmingEfficient/low-level programming–Large programsLarge programs66Typing and ProductivityTyping and Productivity[Ousterhout, 97][Ousterhout, 97]77PerlPerl•Perl was written by Larry Wall in 1986. Perl was written by Larry Wall in 1986. –He continues to develop and maintain the languageHe continues to develop and maintain the language–It is available on virtually every computer platform, from It is available on virtually every computer platform, from Apple Macintosh to VMS. Apple Macintosh to VMS. •Perl is an acronym for: Perl is an acronym for: –"Practical Extraction and Report Language""Practical Extraction and Report Language"– or, jokingly, "Pathologically Eclectic Rubbish Lister" or, jokingly, "Pathologically Eclectic Rubbish Lister" –It started out as a scripting language to supplement It started out as a scripting language to supplement rnrn, the , the ubiquitous USENET reader, which Wall also wrote.ubiquitous USENET reader, which Wall also wrote.•It is an interpreted language that is optimized for It is an interpreted language that is optimized for string manipulation, I/O, and system tasks. string manipulation, I/O, and system tasks.88CharacteristicsCharacteristics•Occupies the middle ground between a compiled Occupies the middle ground between a compiled language and a traditional interpreted languagelanguage and a traditional interpreted languagePerl scriptPerl scriptPerl reads entire scriptPerl reads entire scriptConverts to compact intermediate formConverts to compact intermediate form(a tree structure)(a tree structure)ExecutesExecutes99Perl can be simplePerl can be simple Perl can make simple programs much Perl can make simple programs much shorter, and easier to write. shorter, and easier to write. C codeC code Perl codePerl code #include <stdio.h> #include <stdio.h> print "Hello World\n"; print "Hello World\n"; main() { main() { printf("Hello World\n"); printf("Hello World\n"); } } Comments are proceeded by the # character, Comments are proceeded by the # character, and and continue until the end of the line. Statements continue until the end of the line. Statements end end in a semi-colon.in a semi-colon.$J = 333; # assigns the value 33 to the $J = 333; # assigns the value 33 to the scalar J scalar J1010Running a Perl programRunning a


View Full Document

UNCA CSCI 431 - Introduction to Scripting Languages and Perl Basics

Download Introduction to Scripting Languages and Perl Basics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Scripting Languages and Perl Basics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Scripting Languages and Perl Basics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?