Perl Practical Extraction and Report Language

Slides:



Advertisements
Similar presentations
1/12 Steven Leung Very Basic Perl Tricks A Few Ground Rules File I/O and Formatting Operators, Flow Control Statements Regular Expression Subroutines Hash.
Advertisements

A Guide to Unix Using Linux Fourth Edition
Adv. UNIX:Perl/81 Advanced UNIX v Objectives of these slides: –introduce Perl (version ) –mostly based on Chapter 1, Learning Perl
CSC 4630 Perl 1. Perl Practical Extraction and Support Language A glue language under UNIX Written by Larry Wall Claimed to be the most portable of scripting.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Ted Pavlic and Joe Ryan.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
I/O while ($line= ){ #remove new line char \n chomp($line); if($line eq “quit”){ exit(1); } while ( ){ #remove new line char \n chomp($_); if($_ eq “quit”){
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
Perl Programming WeeSan Lee
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Introduction to Perl Programming Morris Law December 8, 2012.
Control Structures. Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Robert Mohr, Ted Pavlic, and Joe Ryan.
Perl By Gabe and Ted. History Perl was created by Larry Wall while working at NASA’s Jet Propulsion Labs. Larry Wall also created patch which is in widespread.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Web Programming for DB Applications Yuen-Hsien Tseng 2006/04/18.
1 Perl Syntax: control structures Learning Perl, Schwartz.
Introduction to Perl Yupu Liang cbio at MSKCC
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introduction to Perl William G. Dishman CUR/516 November 5, 2014.
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Chapter 11: Perl Scripting Off Larry’s Wall. In this chapter … Background Terminology Syntax Variables Control Structures File Manipulation Regular Expressions.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Getting started in Perl: Intro to Perl for programmers Matthew Heusser – xndev.com - Presented to the West Michigan Perl User’s Group.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
Scripting Languages ● Perl, Python, Unix Shell, VB, JavaScript, etc. ● Glue Languages. ● Typeless. ● Interchangeable Code and Data. ● Interpreted vs. Compiled.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
CSI605 perl. Perl Facts Perl = Pathologically Eclectic Rubbish Lister Perl is highly portable across many different platforms and operating systems Perl.
The Scripting Programming Language
Perl Subroutines User Input Perl on linux Forks and Pipes.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Organization of Programming Languages Meeting 37 April 18, 2016.
Regular Expressions Copyright Doug Maxwell (
CSE 374 Programming Concepts & Tools
Looking for Patterns - Finding them with Regular Expressions
PERL.
PERL.
Süsteemprogrammeerimine keeles C ja C#
An Introduction to Perl
C keel AVR mikrokontrolleril
Pemrosesan Teks Herika Hayurani Sept 19, 2006
Lesson 2. Control structures File IO - reading and writing Subroutines
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
C keel AVR mikrokontrolleril
AKA LET'S WRITE SOME FUCKING PERL by William Orr
INTRODUCTION to PERL PART 1.
Presentation transcript:

Perl Practical Extraction and Report Language Nikita Shipilov, 2008

Keelest Dünaamiline programeerimiskeel Protseduraalne, ning toetab nüüd ka objektorienteeritud programmeerimist Esimene release aastal 1987 Sai tuntuks oma jõulise regulaaravaldiste mootori pärast Kasutatakse tekstitöötluses

Keelest Mõjutatud keeltest: AWK, BASIC, BASIC- PLUS, C, C++, Lisp, Pascal, sed, Unix shell Mõjutas: Python, PHP, Ruby, ECMAScript, Dao, Windows PowerShell OS: cross-platform Litsentsid: GNU General Public License, Artistic License

Looja Larry Wall http://en.wikipedia.org/wiki/Larry_Wall

Ajalugu 1987 – Perl 1.0 1988 – Perl 2 uuendatud regulaaravaldiste mootor 1989 – Perl 3 on lisatud binaarandmete tugi 1991 – Programming Perl esimene de facto manuaal 1993 – Perl 4.036

Ajalugu 1994 – Perl 5 uus interpretaator, on lisatud mõned uued komponendid (objektid, viidad, leksikaalsed muutujad, moodulid), Unicode tugi, vood, on laiendatud OOP tugi 1995 – (CPAN) Comprehensive Perl Archive Network on loodud ühine repositoorium Perl moodulitele (praegu umbes 11 000 skripti 5 000 autorilt)

Ajalugu 2007 – Perl 5.10.0 switch-käsk "smart match operator" ~~ Perl 6 ???

Tunnused Perl on esialgselt loodud tekstitöötluseks Täna aga keelt kasutatakse paljude laie- mate probleemide lahendamiseks (süstee- mide administreerimiseks, võrkude seadi- stamiseks, GUI, ...) Perl osutub olema rohkem praktiline kui ilus!

Tunnused Üldine Perl’i struktuur on pärit C keelest (muutujad, avaldised, väärtustamine, koodi plokid, subroutines, ...), Listid – Lisp’ist, Hashes – AWK, Regulaaravaldised – sed-keelest.

Hello, World #!/usr/bin/perl print "Hello, world!\n";

Süntaks Perl’i programm koosneb deklaratsioonide järjendist, mis käivitatakse ülalt-alla. Tsüklid, alamrutiinid ja teised struktuurid võimaldavad hüpata erinevate koodi osade vahel. Perl’i süntaktilised elemendid on valitavad, mis tähendab, et programmeerida võib nii nagu tahad!

Süntaks Ainuke asi, mida peab deklareerima, on muutuja: my $a; if ($a) {} Muutuja hoiab undef väärtust seni, kuni temale on määratud mingi väärtus (0 num- brite korral, “” String’ide korral)

Süntaks Alamrutiinide deklareerimine käib järgmi- selt: sub myname; $me = myname $0 or die “…” Samuti võib laadida rutiinide deklaratsioo- nid require või use käskudega.

Süntaks Komentaarid: # Iga käsk peab olema lõpetatud semikoo- loniga. Kui käsk on viimane plokis siis ‘;’ võib mitte panna. Kui plokk on defineeritud “sama koodi sees”, siis selle eraldamiseks on vaja kasu- tada sulge { } if (EXPR) BLOCK if (!open(FOO)) { die "Can't open $FOO: $!"; }

Süntaks Number 0, String ‘’ ja tühi list on undef, ja vastavalt on väärad Boole’i kontekstis. Kõik teised väärtused on tõesed. NB! Sümbolid on case-sensitive!

Andmetüübid Perl’is on sisseehitatud kolm andmetüüpi: skalaarid, skalaaride massiivid ja assotsi- atiivsed massiivid (hashes). Skalaarid on kas sõna, number või viit millegile. Massiivid on järestatud skalaaride listid, mis on indekseeritud numbritega (alates 0- st). Hashes on võtmetega indekseeritud skalaaride kollektsioonid.

Andmetüübid Lisatakse veel failide “käsitlejad” (filehand- les) ja alamrutiinid (subroutines). $foo # a scalar @foo # an array %foo # a hash &foo # a subroutine. FOO # a file handle or constant

Andmetüübid Näide: $name = “joe”; $number = 50; @scores = {1, 10, 25, 15}; %favorite = ( joe => 'red', sam => 'blue' ); # Defining a subroutine sub foo { ... } foo $x, @y, %z;

Standart IO open(IN, "< input.txt") or die "cant open input file: $!"; open(OUT, ">> output.txt") or die "cant open output file: $!"; while ($line = <IN>) { # write data to a file print OUT $line; } close(IN); close(OUT); print "$filename exists" if (-e $filename); print "$filename file size is ".(stat $filename)[7]; @txtfiles = <*.txt>; # perl globbing @txtfiles = `dir /b *.txt`; # or use the shell (slower), needs chomping

Struktuurid Peamised struktuurid, mis kasutatakse voo kontrollimiseks, on järgmised: if (EXPR) BLOCK if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK LABEL while (EXPR) BLOCK LABEL while (EXPR) BLOCK continue BLOCK LABEL until (EXPR) BLOCK LABEL until (EXPR) BLOCK continue BLOCK LABEL for (EXPR; EXPR; EXPR) BLOCK LABEL foreach VAR (LIST) BLOCK LABEL foreach VAR (LIST) BLOCK continue BLOCK LABEL BLOCK continue BLOCK

Struktuurid Rohkem informatsiooni: Ja operaatorite kohta: http://search.cpan.org/dist/perl/pod/perlsyn.pod Ja operaatorite kohta: http://search.cpan.org/dist/perl/pod/perlop.pod

Regulaaravaldised Regulaaravaldiste mootor Perl’is põhineb backtracking algoritmil (brute-force). Avaldiste süntaks oli esialgselt võetud Unix Version 8 süsteemist. Kuid praegu Perl’i regexp pakub palju rohkem võimalusi.

Regulaaravaldised Võrdlusoperatsioonid saavad kasutada erinevaid laiendeid (modifiers): m – uuri teksti kui mitmerealist sõnet, s – üherealine sõne, i – case-insensitive pattern matching x – luba tühikuid ja kommentaare p – hoia ${^PREMATCH}, {$^MATCH} ja ${^POSTMATCH} edasiseks kasutamiseks g ja c – globaalne võrdlus, kursor samal kohal

Regulaaravaldised Metasümbolid: \ Quote the next metacharacter ^ Match the beginning of the line . Match any character (except newline) $ Match the end of the line (or before newline at the end) | Alternation () Grouping [] Character class

Regulaaravaldised Kvantorid: * Match 0 or more times ? Match 1 or 0 times {n} Match exactly n times {n,} Match at least n times {n,m} Match at least n but not more than m times

Regulaaravaldised *? Match 0 or more times, not greedily ?? Match 0 or 1 time, not greedily {n}? Match exactly n times, not greedily {n,}? Match at least n times, not greedily {n,m}? Match at least n but not more than m times, not greedily

Regulaaravaldised “Greedy" tähendab seda, et avaldisi otsitakse teksti lõpuni, ja tagastatakse pärast ainult etteantud matching’ute arv.

Regulaaravaldised Possessiivkvantorid: *+ Match 0 or more times and give nothing back ++ Match 1 or more times and give nothing back ?+ Match 0 or 1 time and give nothing back {n}+ Match exactly n times and give nothing back (redundant) {n,}+ Match at least n times and give nothing back {n,m}+ Match at least n but not more than m times and give nothing back

Regulaaravaldised Sümbolite klassid: http://search.cpan.org/dist/perl/pod/perlre.pod#___top

Regulaaravaldised Näide: my $email = "this.is\@my-email.id"; if ($email =~ /(.+)@(.+)\.(.{2,4})/) { print "E-mail : $email\n"; print "ID : $1\n"; print "Domain : $2\n"; print "Tail : $3\n"; } E-mail : this.is@my-email.id ID : this.is Domain : my-email Tail : id

Smart matching $b ~~ $a: $a $b Type of Match Implied Matching Code ====== ===== ===================== ============= Code[+] Code[+] referential equality $a == $b Any Code[+] scalar sub truth $b->($a) Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b] Hash Array hash slice existence grep {exists $a->{$_}} @$b Hash Regex hash key grep grep /$b/, keys %$a Hash Any hash entry existence exists $a->{$b} Array Array arrays are identical[*] Array Regex array grep grep /$b/, @$a Array Num array contains number grep $_ == $b, @$a Array Any array contains string grep $_ eq $b, @$a

Smart matching $b ~~ $a: $a $b Type of Match Implied Matching Code ====== ===== ===================== ============= Any undef undefined !defined $a Any Regex pattern match $a =~ /$b/ Code() Code() results are equal $a->() eq $b->() Any Code() simple closure truth $b->() # ignoring $a Num numish[!] numeric equality $a == $b Any Str string equality $a eq $b Any Num numeric equality $a == $b Any Any string equality $a eq $b ! - either a real number, or a string that looks like a number

Viited http://www.perl.com http://www.perl.org http://en.wikipedia.org/wiki/Perl http://www.google.com

Tänan!