1 / 18

Perl Practical Extraction and Report Language

Perl Practical Extraction and Report Language. Shell-level scripting language: Glue that ties together programs written in other languages. Perl: Developed by Larry Wall in the late 1980s. Builds on... sh awk sed c. Perl and the Web.

cwen
Download Presentation

Perl Practical Extraction and Report Language

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. PerlPractical Extraction and Report Language Shell-level scripting language: Glue that ties together programs written in other languages. Perl: Developed by Larry Wall in the late 1980s. Builds on... sh awk sed c CSE 341 - S. Tanimoto Perl-Intro -

  2. Perl and the Web One-pass compilation means Perl programs can be efficiently compiled on demand. Perl makes it easy to process text (and generate HTML!). With contributed modules in the CPAN library, Perl has become a defacto standard for CGI programming on the Web, esp. on Unix servers. CSE 341 - S. Tanimoto Perl-Intro -

  3. Perl vs Java Server vs Client... Input info may be too sensitive to send over the net to an applet. Applet downloading and startup cause high latency. No special browser plugins are needed, since Perl doesn’t run in the browser. CSE 341 - S. Tanimoto Perl-Intro -

  4. Perl has a “Little Language” philosophy Small numbers of variables means less concern about name conflicts... declarations not required. Perl grows out of a systems-programming context. Conciseness was valued over transparency. The meanings of language features are often dependent on context (e.g., list context vs scalar context). One system may consist of many Perl scripts. CSE 341 - S. Tanimoto Perl-Intro -

  5. Comments on the Book by Schwartz and Christiansen Learning Perl, 2nd edition, is a relatively recent book (1997). It covers Perl 5, the latest version and not completely compatible with version 4. “A gentle introduction to Perl” The companion book is Programming Perl, 3rd edition, by Larry Wall, Tom Christiansen and Jon Orwant. CSE 341 - S. Tanimoto Perl-Intro -

  6. Running a Perl Program #!/usr/bin/perl print("Out of the oyster!\n"); # comment Make sure the file is executable: chmod +x howdy.pl Run the program from the command line: ./howdy.pl CSE 341 - S. Tanimoto Perl-Intro -

  7. A Perl Script for the Web #!/usr/bin/perl print "Content-type: text/html\n\n"; $now = localtime(); print "<html><body>"; print "<h2>The time is $now\n"; print " </h2></body></html>"; CSE 341 - S. Tanimoto Perl-Intro -

  8. Online help perldoc perl (overview) perldoc perlfaq (freq. asked questions) perldoc perldata (data structures) perldoc perlsyn (syntax) perldoc perlop (operators and precedence) perldoc perlre (regular expressions) perldoc perlrun (execution and options) perldoc -f split (info on a function) CSE 341 - S. Tanimoto Perl-Intro -

  9. The Fundamental Data Types $n = 25; # a numeric scalar $str = "Here is a string"; print('The value of $n is ' . $n); # Note strings with '' do not have # variable "interpolation" performed # But strings with "" DO have it. print("The value is $n."); CSE 341 - S. Tanimoto Perl-Intro -

  10. String Operations "string1" . "string2" # concatenation Can also be done using interpolation: $str1 = "abc"; $str2 = "def"; $newstr = "$str1$str2"; CSE 341 - S. Tanimoto Perl-Intro -

  11. Support for processing text: Immediate, embedded (“Here”) Documents print << "END-OF-PRINT"; Hello there. This is a two-line immediate text doc. END-OF-PRINT CSE 341 - S. Tanimoto Perl-Intro -

  12. Choice of Interpolating or Not $dollars = 64000; print <<”EOT”; The $dollars question. Are $dollars printed out here? EOT CSE 341 - S. Tanimoto Perl-Intro -

  13. Choice of Interpolating or Not $dollars = 64000; print <<’EOT’; The $64000 question. Are $dollars printed out here? EOT CSE 341 - S. Tanimoto Perl-Intro -

  14. Interpolation -- Not The $64000 question. Are $dollars printed out here? CSE 341 - S. Tanimoto Perl-Intro -

  15. Arrays @trees = ("Oak", "Maple", "Madrona"); @moretrees = qw(pine alter hemlock); @ages = (75, 50.5, "twenty"); $mytree = $trees[1]; # "Maple" CSE 341 - S. Tanimoto Perl-Intro -

  16. Hashes (Associative Arrays) $foodtype{"Spaghetti"} = "Italian"; $thetype = $foodtype{"Spaghetti"}; foreach $food (keys %foodtype) { $thetype = $foodtype{$food}; print "Food $food is $thetype\n"; } CSE 341 - S. Tanimoto Perl-Intro -

  17. Quick Example of CGI Processing:The HTML Form <html><body> <form method=post action="http://www.domain.edu/do-something.pl"> Type your user name: <input type=text name=username size=20> <input type=submit value="Click here"> </form> </body></html> CSE 341 - S. Tanimoto Perl-Intro -

  18. CGI Processing:The Perl Script #!/usr/bin/perl use CGI qw/:standard/; $theName = param("username"); print "Content-type: text/html\n\n"; print " <html><body><h2>"; print " Your user name is $theName"; print "</h2></body></html>"; CSE 341 - S. Tanimoto Perl-Intro -

More Related