practical extraction and report language perl is a
play

Practical Extraction and Report Language Perl is a language of - PowerPoint PPT Presentation

Practical Extraction and Report Language Perl is a language of getting your job done There is more than one way to do it Larry Wall VI, March 2005 Page 1 Practical Extraction and Report Language http://perl.oreilly.com "


  1. Practical Extraction and Report Language « Perl is a language of getting your job done » « There is more than one way to do it » Larry Wall VI, March 2005 Page 1

  2. Practical Extraction and Report Language http://perl.oreilly.com " Perl is both a programming language and an application on your computer that runs those programs " VI, March 2005 Page 2

  3. Perl history A few dates: 1969 UNIX was born at Bell Labs. 1970 Brian Kernighan suggested the name "Unix" and the operating system we know today was born. 1972 The programming language C is born at the Bell Labs (C is one of Perl's ancestors). 1973 “grep” is introduced by Ken Thompson as an external utility: Global REgular expression Print. 1976 Steven Jobs and Steven Wozniak found Apple Computer (1 April). 1977 The computer language awk is designed by Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan (awk is one of Perl's ancestors). VI, March 2005 Page 3

  4. Perl history 1987 Perl 1.000 is unleashed upon the world NAME perl | Practical Extraction and Report Language SYNOPSIS perl [options] filename args DESCRIPTION Perl is a interpreted language optimized for scanning arbitrary text files , extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author's opinion, anyway) some of the best features of C, sed, awk, and sh , so people familiar with those languages should have little difficulty with it (Language historians will also note some vestiges of csh, Pascal, and even BASIC|PLUS). Expression syntax corresponds quite closely to C expression syntax. If you have a problem that would ordinarily use sed or awk or sh, but it exceeds their capabilities or must run a little faster, and you don't want to write the silly thing in C, then perl may be for you. There are also translators to turn your sed and awk scripts into perl scripts OK, enough hype. VI, March 2005 Page 4

  5. Perl history 1994 Perl5: last major release (Currently Perl 5.8.6). 1996 Creation of the CPAN repository of modules and documentation ( Comprehensive Perl Archive Network). 2005 Perl 5.8.6 Supported Operating Systems: Unix systems / Macintosh (OS 7-9 and X) / Windows / VMS Perl Features Perls database integration interface (DBI) supports thirdparty databases including Oracle, Sybase, Postgres, MySQL and others. Perl works with HTML, XML, and other markup languages . Perl supports Unicode. Perl is Y2K compliant. Perl supports both procedural and objectoriented programming. Perl interfaces with external C/C++ libraries through XS or SWIG. Perl is extensible There are over 500 third party modules available from (CPAN). VI, March 2005 Page 5

  6. Perl history Perl and the Web Perl is the most popular web programming language due to its text manipulation capabilities and rapid development cycle. Perl's CGIpm module, part of Perl's standard distribution, makes handling HTML forms simple. Perl can handle encrypted Web data, including ecommerce transactions. Perl can be embedded into web servers (mod_perl) to speed up processing by as much as 2000%. Perl's DBI package makes webdatabase integration easy. VI, March 2005 Page 6

  7. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; The first line of a Perl program is called "command interpretation" or "Shebang line". This line refers to the "#!" and tells the computer that this is a Perl program. To find out whether you should use /usr/bin/perl OR /usr/local/bin/perl , type: " which perl " in your shell: computerX: vioannid$ which perl computerY: vioannid$ which perl /usr/bin/perl /usr/local/bin/perl VI, March 2005 Page 7

  8. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world " print "Hello world" ; #tell the program to exit exit ; use strict; A command like use strict is called a pragma. Pragmas are instructions to the Perl interpreter to do something special when it runs your program. "use strict" does two things that make it harder to write bad software: It makes you declare all your variables, and it makes it harder for Perl to mistake your intentions when you are using subroutines ALL STATEMENTS ENDS IN A SEMICOLON ";" (similar to the use of the period "." in the English language) VI, March 2005 Page 8

  9. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; use warnings; Comments are good, but the most important tool for writing good Perl is the "warnings". Turning on warnings will make Perl yelp and complain at a huge variety of things that are almost always sources of bugs in your programs. Perl normally takes a relaxed attitude toward things that may be problems: it assumes that you know what you're doing, even when you don't … VI, March 2005 Page 9

  10. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; Comments All lines starting with "#" are not taken into account in the execution of the program. Good comments are short , but instructive They tell you things that aren't clear from reading the code. Blank lines or spaces are also not taken into account in the execution of the program. However, they help in the reading of the code. VI, March 2005 Page 10

  11. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; Print statement: … prints ! By default, the standard output is the shell window from which the program is executed. ALL STATEMENTS ENDS IN A SEMICOLON ";" (similar to the use of the period "." in the English language) VI, March 2005 Page 11

  12. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; The exit statement: Tells the computer to exit the program. Although not explicitely required in Perl, it is definitely common. VI, March 2005 Page 12

  13. Perl Hello world ! My first program (hello.pl): #!/usr/local/bin/perl use strict; use warnings; #tell the program to print "Hello world" print "Hello world" ; #tell the program to exit exit ; output: (Do not forget to make the file executable: vioannid$ chmod a+x perl_01.pl ) vioannid$ ./perl_01.pl Hello worldvioannid$ VI, March 2005 Page 13

  14. Perl Hello world !! Print: vioannid$ ./perl_02.pl #!/usr/local/bin/perl Hello world use strict; Hello world use warnings; Helloworld vioannid$ #play with the print statement #words separated by newline print "Hello\nworld\n" ; #words separated by tabs & a final newline print "Hello\tworld\n" ; #usage of the period to cat strings print "Hello"."world"."\n"; Important: Unix & all Unix flavors: \n #tell the program to exit exit ; Mac OS : \r Windows: \r\n VI, March 2005 Page 14

  15. Perl variables Perl has 3 data types: scalars / arrays / hashes scalars a single string (of any size, limited only by the available memory), or a number, or a reference to something Scalar values are always named with '$ ' (even when referring to a scalar that is part of an array or a hash). The '$' symbol works semantically like the English word "the" in that it indicates a single value is expected . my $variable_1 = "Hello world !\n"; #note the quotes my $variable_two = 30; #note the absence of quotes my $marks[4]; # the fifth element of the array "marks" VI, March 2005 Page 15

  16. Perl variables Perl has 3 data types: scalars / arrays / hashes arrays (of scalars) Normal arrays are ordered lists of scalars indexed by number (starting with 0). Entire arrays are denoted by ' @ ', which works much like the word "these" or "those" does in English, in that it indicates multiple values are expected . my @numbers = ("One", "Two", "Three", "Four", "Five"); my @numbers = (1..5); #same as "@numbers = (1, 2, 3, 4, 5);" my $numbers[0] = "One"; my $numbers[1] = "Two"; … my @anyarray = (6, "hello", @numbers); index 0 1 2 3 4 … value One Two Three Four Five VI, March 2005 Page 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend