120 likes | 173 Views
Programming Language Concepts Perl Introduction. Adapted by Carl Reynolds from materials by Sean P. Strout. What is Perl?. P ractical E xtraction and R eport L anguage Originally developed by Larry Wall in the mid-1980’s to produce reports from a Usenet-like bug reporting system
E N D
Programming Language ConceptsPerl Introduction Adapted by Carl Reynolds from materials by Sean P. Strout PLC - Perl Introduction (v2.01)
What is Perl? • Practical Extraction and Report Language • Originally developed by Larry Wall in the mid-1980’s to produce reports from a Usenet-like bug reporting system • Why didn’t he just use another language? • Wanted the quickness of shell coding combined with the power of advanced Unix tools like grep, cut, sort, awk & sed • Could compromise some speed for flexibility • Needed a bridge between low-level (C, C++, Assembly) and high-level (shell) programming • 4 claims about Perl • Perl is easy • Perl is nearly unlimited • Perl is mostly fast • Perl is ugly (but so are camels) PLC - Perl Introduction (v2.01)
Is Perl Easy or Hard? • You be the judge while (<>) { chomp; print join(“\t”, (split /:/)[0, 2, 1, 5] ), “\n”; } (Put tabs where there are colons, and prints the first, third, second, and sixth elements of the resulting list, followed by a newline.) • The language usually sides with the Perl programmer vs. the Perl student • “You learn Perl once, but you use it again and again!” • Perl is a very high level language • Roughly 30-70% as long as a counterpart program in C • And we all know shorter source code means fewer bugs • (if you can read it) PLC - Perl Introduction (v2.01)
Is Perl Easy or Hard? • “Perl looks like line-noise to the uninitiated, but to the seasoned programmer, it looks like check-summed line-noise with a mission in life” • Oh, and then there’s the Obfuscated Perl Contest • The game Frogger, using Perl, in less than 2048 characters: evalevalq.q>trd!Uj:%L<061:%C<csnvo:%f<fsddo0:%c<cmtd:%x<xdmmnv:%I<011:%u<251:%bs<bsd`udSdbu`ofmd:%w<lnwd:%U<2:%t<L`hoVhoenv,? odv),idhfiu<?314-,vheui<?254(:%b<%t,?B`ow`r:%b,?bnoghftsd),vheui<?%u-,idhfiu<?311(:%b,?q`bj)(:s)3-3-%u-001-%c(:s)3-081-%u-311 -%f(:s)3-001-%u-031-%f(:s)3-1-%u-34-%f(:gns)%{<1:%{=%u:%{*<71(zs)%{-01-%{*51-54-%f-%f(:|s)3-1-%u-04-cm`bj(:%b,?%bs)3-1-%u-311 (:%G<,041:v)1-%L-31-C-%x(:v)%G-%L-,021-C-%x(:%B<,91:v),31-041-,4-B-%c(:v),91-041-,74-B-%c(:%E<,%I:v)1-021-31-E-%x(:v),%I-021-, 91-E-%x(:%K<,231:v),71-81-,31-@-%C(:v),301-81-,%L-@-%C(:v),%u-81-,211-@-%C(:%M<,%u:v),51-61-1-F-%C(:v),%L-61-,021-F-%C(:v),%u -61-,211-F-%C(:%J<%u:v)751-41-791-[-%C(:v)401-41-441-[-%C(:v)%u-41-291-[-%C(:%b,?bsd`udNw`m)063-080-091-088-,u`fr<?G-,ghmm<?f sddo5(:S)1(:%b,?sdqd`u)%I-]'t(:%t,?choe)&=Envo?&<?rtczS),0(:'V:%b,?%w)G-1-31(hg)%x=081(:|(:%t,?choe)&=Tq?&<?rtczS)0(:%b,?%w)G -1-,31(:|(:%t,?choe)&=Mdgu?&<?rtcz'V:%b,?%w)G-,31-1(hg)%y?31(:|(:%t,?choe)&=Shfiu?&<?rtcz'V:%b,?%w)G-31-1(hg)%Y=%u,31(:|(:L`h oMnnq)(:dyhu:rtc!vz%b,?%bs)%^Z1\-%^Z0\-%^Z3\-%^Z0\*8-,u`fr<?%^Z2\-,ghmm<?%^Z5\(:|rtc!tzhg)%G?%u(z%G*<%L:%d<,%G:%G<,%L:|dmrdz% G*<01:%d<01:|%b,?%w)C-%d-1(:hg)%B?%u(z%B*<%I:%d<,%B:%B<,%I:|dmrdz%B*<01:%d<01:|%b,?%w)B-%d-1(:hg)%E?%u(z%E*<031:%d<,%E:%E<,03 1:|dmrdz%E*<01:%d<01:|%b,?%w)E-%d-1(:hg)%K?%u(z%K*<229:%d<,%K:%K<,251:|dmrdz%K*<7:%d<7:|%b,?%w)@-%d-1(:hg)%M?%u(z%M*<271:%d<, %M:%M<,271:|dmrdz%M*<9:%d<9:|%b,?%w)F-%d-1(:hg)%J=,%u(z%J,<%u:%d<,%J:%J<%u:|dmrdz%J,<7:%d<,7:|%b,?%w)[-%d-1(:'V:hg)%x=081(zhg ))%x?031(}})%x=001((zAn<%b,?ghoe)nwdsm`qqhof-%y-%x-%Y-%X(:hg)%x?031(zhg)%"n(z'R:||dmrdzhg)%x?58(zhg)%"n?0(z%n<7:%n*<3hg)%x=81 (:%n<,7hg)%x=61(:%b,?%w)G-%n-1(:|dmrdz'R:||dmrdzhg)%"n?0(z'R:|dmrdzS)00(:%U**:%O**:'R:v)%y-%x-%Y-Q-%f(:%b,?edmdud)&Q&(hg))%O$ 4((:||||rmddq)4(''Uj;;dyhu)1(hg)%U=0(:||rtc!Rz%U,,:qshou#]`#:%b,?%w)G-063,%y-081,%x(:|rtc!SzP)cm`bj(:%R*<%^Z1\:P)sde(: |rtc!P z%b,?bsd`udUdyu)%L-9,udyu<?%R/1-,ghmm<?%^Z1\(:|rtc!sz%b,?%bs)%^Z1\-%^Z0\-%^Z3\-%^Z2\-,ghmm<?%^Z5\-,ntumhod<?%^Z4\(:|rtc!Vz)%y -%x-%Y-%X(<%b,?bnnser)G(:|>^chr($$/$$)x2016 PLC - Perl Introduction (v2.01)
Is Perl easy or hard? • "I believe that learnability is a laudable goal, but frequently misplaced. The purpose of a language is not to help you learn the language, but to help you learn other things by using the language. We don't water down English to make it easy to learn. We prefer English to remain a rich language, quirky, sloppy, and full of redundancy. Same for Perl." (Larry Wall) • "If you want to do beautiful art, you don't go out and buy a beautiful canvas, and a beautiful brush, and a beautiful palette, and slather beautiful paints on it. If you want to write beautiful poetry, this doesn't happen because you started with a beautiful language. Languages are an artistic medium. I don't want Perl to be beautiful--I want you to write beautiful programs in Perl." (Larry Wall) PLC - Perl Introduction (v2.01)
The State of Perl Today • A huge community with respect to online documentation, published books, newsgroups, mailing lists and implementations • “Perl will always be free” • Larry is still in charge of Perl, but its development is guided by approximately 30 key people around the world • “Common things should be easy; advanced things should be at least possible” • Comprehensive Perl Archive Network • Perl source, examples, documentation, extensions, archive, messages, etc. • tutorials, references and examples • Usenet - comp.lang.perl.* PLC - Perl Introduction (v2.01)
The Good and the Bad • What is Perl good for? • Perl is ideal for problems working with 90% text • Perl is married to the web • Allows rapid movement of documents to HTML format • It is the darling language for CGI scripts run on a web server • "The duct tape of the internet" • What is Perl not good for? • Can’t make an opaque binary, so company trade secret algorithms are off limits • Never say can’t with Perl. There actually is a perl bytecode compiler • Real-time systems programming or user interface design is better suited to C or Java PLC - Perl Introduction (v2.01)
What is Perl for? • "Perl is a language for getting your job done." (Learning Perl) • "I picked the feature set of Perl because I thought they were cool features. I left the other ones behind because I thought they sucked." (Larry Wall) • "English is useful because it's a mess. Since English is a mess, it maps well onto the problem space, which is also a mess, which we call reality. Similarly, Perl was designed to be a mess (though in the nicest of possible ways)." (Larry Wall) • "People like things to be visually distinct from their surroundings. That is also why the various classes of operators and variables in Perl are visually distinct from each other. It's just sound human engineering, as far as I'm concerned. I don't like the fact that all the operators look the same in Lisp." (Larry Wall) PLC - Perl Introduction (v2.01)
Making a Perl Program • hello.pl #!/usr/bin/perl print “Hello, world!\n”; • The first line is a special comment indicating the program to execute the text file • Use #!perl on non-unix machines • (treated as just a comment on the PC) • There is no main routine • There’s no required variable declaration section • The second line is a semi-colon terminated statement PLC - Perl Introduction (v2.01)
Revision History • Revision History • v1.00, 10/6/2003 11:47 AM, sps Initial revision. • v1.01, 10/7/2003 12:53 PM, sps Slide 3 incorrect. -- v2.00, 1/9/2005, chr -- v2.01, 10/25/2006, chr PLC - Perl Introduction (v2.01)