1 / 5

Perl

Perl. Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 3.3.3 Appendix A.9. Perl overview. Perl (Practical Extraction and Report Language) is an interpreted language designed for efficient text-processing applications

parsley
Download Presentation

Perl

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. Perl Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 3.3.3 Appendix A.9

  2. Perl overview • Perl (Practical Extraction and Report Language) is an interpreted language designed for efficient text-processing applications • It was developed by Larry Wall in 1986 • It was originally called PEARL, but a conflict with an existing graphics language resulted in the shortening of the name • The language includes pattern matching, file handling, and scalar data • It has syntax patterned after C and was originally designed to operate as a shell script • Its power is that it views programs and files as data • It has proven to be an effective language for interacting with Web pages

  3. Perl structure • Variables in Perl are either integers or strings and begin with the symbol $. • A simple Perl program consists of a series of print statements. • It has the usual sequence of control structures such as for, while, and until loops and if conditional. • Perl shares an ability to process regular expressions like several other process languages • Example use: $ENV{'USER'} = ‘mvz’ • will be true if login name mvz is the string $ENV{'USER'} (i.e., is the user running this program). • This shows how Perl can interact with the system environment

  4. Perl example 1 #!/usr/bin/perl 2 @inputdata = split(/ /, <STDIN>); 3 $count = 0; 4 foreach $nextone (@inputdata) 5 {print "$nextone"; 6 $count = $count + $nextone;}; 7 print "Sum = "; 8 print "$count\n"; Figure A.14 in text

  5. Perl regular expressions • Perl provides a direct translation of regular expressions. • For example, the regular expression a+b+ is the following Perl script: • #!/usr/bin/perl # This is a Perl script • $_ = <STDIN>; # Read in input to argument $_ • if (/a+b+$/) then { print “yes\n”;} • else { print “no\n”;} # Match $_ with a+b+ • The pattern /X/ is matched against the string argument. • This pattern succeeds if the regular expression a+b+ extends from the initial character of the input line () to the end of the input line ($). • To succeed if a+b+ is contained within a string, we • only need the pattern /a+b+/.

More Related