230 likes | 360 Views
Perl R and SQL for the very beginners. Christoph Rau, Calvin Pan and Yehudit Hasin Dec 2011. What we do and do not intend to teach. DO. DO NOT. Make you change career to a programmer Replace self – learning process Make you an expert. Get you started as painlessly as possible
E N D
Perl R and SQL for the very beginners Christoph Rau, Calvin Pan and Yehudit Hasin Dec 2011
What we do and do not intend to teach DO DO NOT Make you change career to a programmer Replace self – learning process Make you an expert • Get you started as painlessly as possible • Make you able to write simple, usable and sustainable code for yourself • Make you comfortable to expand your knowledge on your own • Give you the right address(es) for asking questions
Dates • 12/8 – Introductions + Perl1 - Yehudit • 12/15 – Perl 2 – Yehudit • 12/22-12/29 – NO MEETINGS • 1/5 – Perl 3 – Yehudit • 1/12 – Perl 4 – Yehudit • 1/19 – R 1 - Christoph • 1/26 – R2 - Christoph • 2/2 – R3 – Christoph • 2/9 – SQL1 - Calvin • 2/16 –SQL2 - Calvin
Today • Introduction • Why Perl/R/SQL? • What is a programing language? • GPP – good programming practice • Perl 1 • My first program • Data types • Data organization • Simple operators
Why Perl/R/SQL and not Excel? • Responsibility • More work • Safety • Flexibility • Speed • Reproducibility
Why Perl& R& SQL? Perl Manipulation of LARGE data files Text patterns Fast R SQL Statistical analysis Graphing capabilities Analysis packages Efficient data storage and retrieval
What is “programming” and why it is a language? “Language” – The words, their pronunciation, and the methods of combining them used and understood by a community A body of words and the systemsfor their use common to a people who are of the same community or nation, the same geographical area, or the same cultural tradition: the two languages of Belgium; a Bantu language; the French language; the Yiddish language. The system of linguistic signs or symbols considered in the abstract. Any set or system of such symbols as usedin a more or less uniform fashion by a number of people, who are thus enabled to communicate intelligibly with one another. Any system of formalized symbols, signs, sounds, gestures, or the like used or conceived as a means of communicating thought, emotion, etc.
Adapt your thinking • Personal interpretation • Associative thinking • Initiative • Learning from past experience Computer does EXACTLY and EVERYTHING you tell it to
What is wrong with that program? “I would like you to clean my desktop” Clean (desktop);
What is wrong with that program? • “Go to desktop folder” • “For each file examine if it has the words “data”, when it was last opened and size” • If opened more than a year ago and is smaller than 1Mb and does not contain the word “data” – delete.
Why Perl/R/SQL and not Excel? • Responsibility • More work • Safety • Flexibility • Speed • Reproducibility
Good Programming Practice Good Bad and ugly • Have a dedicated folder to optimize your scripts • Have a small file, with similar structure to the data file, to test your script (usually just get sample rows). • Give meaningful names to scripts, variables, files etc… • Document your code • Backup, backup………really BACKUP • Run scripts in any directory higher than Desktop • Optimize your script on a REAL data file • Use “temp”, “x”, “David1” or similar for naming • Assume that your script is perfect
Perl – “Beginning Perl”(Simon Cozens, Peter Wainwright) Resources The main perl website http://www.perl.org/ The book I use as scaffold …/books/beginning-perl/ Very good documentation for all perl functions http://perldoc.perl.org/ The best forum about perl for all levels http://www.perlmonks.org/ For modules and their documentation: http://www.cpan.org/
What I hope to cover • Data types • Data structures – variable, array, hash • Loops and conditional statements – “if”, “for”, “foreach”, “while”, “unless” etc….. • Open, read write and close files • Functions – modules, subroutines • Regular expressions
Perl scripts are simple text files #!/usr/bin/perl use strict; use warnings; print "Hello!!!! :)))"; Get a free editor – the one you will like better Macs: Text Wrangler (simpler) or Komodo…. Windows: Padre, Komodo…..
Tells perl to be more verbal about mistakes in code Tells unix where perl resides #!/usr/bin/perl –w use strict ; use warnings ; print "Hello!!!! :)))\n” ; End of statement Quotations mean it is a string Keyword (a word that is in perl vocabulary, in this case function)
Perl - types of Data Data can be a number or a string Data can be organized in scalar – a single value list – can hold multiple values Perl special signs: $xx= variable – can hold any one value (scalar) @xx= array – can hold multiple values (list).