perl_intro - Introduction to Perl What is Perl? What's Perl...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Perl 1 Introduction to Perl Source: ht p:/ www.domtools.com/svcs/training/perl-intro/slides What is Perl? ± Perl is a High-level Scripting language ± Compiles at run-time ± Available for Unix, PC, Mac ± Best Regular Expressions on Earth What’s Perl Good For? ± Quick scripts, complex scripts ± Parsing & restructuring data files ± CGI-BIN scripts ± High-level programming ± Networking libraries ± Graphics libraries ± Database interface libraries ± BIOINFORMATICS !!! Perl Basics ± Comment lines begin with: # ± First line should look like: #!/bin/perl ± File Naming Scheme ± filename .pl (programs) ± filename .pm (modules) ± Example prog: print “Hello, World!\n”; Perl Basics ± Statements must end with semicolon ± $a = 0; ± Should call exit() function when finished ± Exit value of zero means success ± exit (0); # successful ± Exit value non-zero means failure ± exit (2); # failure Data Types ± Integer ± 25 750000 1_000_000_000 ± 8#100 16#FFFF0000 ± Floating Point ± 1.25 50.0 6.02e23 -1.6E-8 ± String ± ‘hi there’ “hi there, $name” qq(tin can) ± print “Text Utility, version $ver\n”;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Perl 2 Data Types ± Boolean ² 0 0.0 “” represents False ² all other values represents True Variable Types ± Scalar ± $num = 14; ± $fullname = “Cass A. Nova”; ± Variable Names are Case Sensitive ± Underlines Allowed: $Program_Version = 1.0; Variable Types ± List (one-dimensional array) ± @memory = (16, 32, 48, 64); ± @people = (“Alice”, “Alex”, “Albert”); ± First element numbered 0 (can be changed) ± Single elements are scalar: $names[0] = “Ferd”; ± Slices are ranges of elements ± @guys = @people[1. .2]; ± How big is my list? ± print “Number of people: $#people\n”; Variable Types ± Hash (associative array) ± %var = { “name” => “paul”, “age” => 33 }; ± Single elements are scalar ± print $var{“name”}; $var{age}++; ± How many elements are in my hash? ± @allkeys = keys(%var); ± $num = $#allkeys; Operators ± Math ± The usual suspects: + - * / ± $total = $subtotal * (1 + $tax / 100.0); ± Exponentiation: ** ± $cube = $value ** 3; ± $cuberoot = $value ** (1.0/3); ± Bit-level Operations ± left-shift: <<$val = $bits << 1; ± right-shift: >> $val = $bits >> 8; Operators ± Assignments ± As usual: = += -= *= /= **= <<= >>= ± $value *= 5; ± $longword <<= 16; ± Increment: ++ ± $counter++ ++$counter ± Decrement: -- ± $num_tries-- --$num_tries
Background image of page 2
Introduction to Perl 3 Operators ± Boolean (against bits in each byte) ± Usual operators: & | ± Exclusive-or: ^ ± Bitwise Negation: ~ ± $picture = $backgnd & ~$mask | $image; ± Boolean Assignment ± &= |= ^= ± $picture &= $mask; Operators ± Logical (expressions) ² && And operator ² | | Or operator ² ! Not operator ² AND And, low precedence ² OR Or, low precedence ² NOT Not, low precedence ² XOR Exclusive or, low precedence Operators ² Short Circuit Operators ± expr1 && expr2 ² expr1 is evaluated. ² expr2 is only evaluated if expr1 was true. ± expr1 || expr2 ² expr1 is evaluated.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2011 for the course BIOL 1130 taught by Professor Roberts during the Spring '08 term at North Texas.

Page1 / 10

perl_intro - Introduction to Perl What is Perl? What's Perl...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online