Introduction to Perl Day 2 An Introduction to Perl Programming Dave Cross Magnum Solutions Ltd [email_address]
What We Will Cover <ul><li>Types of variable
Strict and warnings
References
Sorting
Reusable Code
Object Orientation </li></ul>
What We Will Cover <ul><li>Testing
Dates and Times
Templates
Databases
Further Information </li></ul>
Schedule <ul><li>09:30 – Begin
11:00 – Coffee break (30 mins)
13:00 – Lunch (90 mins)
14:30 – Begin
16:00 – Coffee break (30 mins)
18:00 – End </li></ul>
Resources <ul><li>Slides available on-line </li><ul><li>http://mag-sol.com/train/public/2009/yapc </li></ul><li>Also see S...
Types of Variable
Types of Variable <ul><li>Perl variables are of two types
Important to know the difference
Lexical variables are created with  my
Package variables are created by  our
Lexical variables are associated with a code block
Package variables are associated with a package </li></ul>
Lexical Variables <ul><li>Created with  my
my ($doctor, @timelords,   %home_planets);
Live in a pad (associated with a block of code) </li><ul><li>Piece of code delimited by braces
Source file </li></ul><li>Only visible within enclosing block
&quot;Lexical&quot; because the scope is defined purely by the text </li></ul>
Packages <ul><li>All Perl code is associated with a package
A new package is created with package </li><ul><li>package MyPackage; </li></ul><li>Think of it as a namespace
Used to avoid name clashes with libraries
Default package is called main </li></ul>
Package Variables <ul><li>Live in a package's symbol table
Can be referred to using a fully qualified name </li><ul><li>$main::doctor
@Gallifrey::timelords </li></ul><li>Package name not required within own package
Can be seen from anywhere in the package (or anywhere at all when fully qualified) </li></ul>
Declaring Package Vars <ul><li>Can be predeclared with  our
our ($doctor, @timelords,   %home_planet);
Or (in older Perls) with  use vars
use vars qw($doctor   @timelords   %home_planet); </li></ul>
Lexical or Package <ul><li>When to use lexical variables or package variables?
Simple answer </li><ul><li>Always use lexical variables </li></ul><li>More complete answer </li><ul><li>Always use lexical...
Except for a tiny number of cases </li></ul><li>http://perl.plover.com/local.html </li></ul>
local <ul><li>You might see code that uses local
local $variable;
This doesn't do what you think it does
Badly named function
Doesn't create local variables
Creates a local copy of a package variable
Can be useful </li><ul><li>In a small number of cases </li></ul></ul>
local Example <ul><li>$/  is a package variable
It defines the record separator
You might want to change it
Always localise changes
{   local $/ = “

”;   while (<FILE> ) {   ...   } } </li></ul>
Strict and Warnings
Coding Safety Net <ul><li>Perl can be a very loose programming language
Two features can minimise the dangers
use strict  /  use warnings
A good habit to get into
No serious Perl programmer codes without them </li></ul>
use strict <ul><li>Controls three things
use strict 'refs'  – no symbolic references
use strict 'subs'  – no barewords
use strict 'vars'  – no undeclared variables
use strict  – turn on all three at once
turn them off (carefully) with  no strict </li></ul>
use strict 'refs' <ul><li>Prevents symbolic references
aka &quot;using a variable as another variable's name&quot;
$what = 'dalek'; $$what = 'Karn'; # sets $dalek to 'Karn'
What if 'dalek' came from user input?
People often think this is a cool feature
It isn't </li></ul>
use strict 'refs' (cont) <ul><li>Better to use a hash
$what = 'dalek'; $alien{$what} = 'Karn';
Self contained namespace
Less chance of clashes
More information (e.g. all keys) </li></ul>
use strict 'subs' <ul><li>No barewords
Bareword is a word with no other interpretation
e.g. word without $, @, %, &
Treated as a function call or a quoted string
$dalek = Karn;
May clash with future reserved words </li></ul>
use strict 'vars' <ul><li>Forces predeclaration of variable names
Prevents typos
Less like BASIC - more like Ada
Thinking about scope is good </li></ul>
use warnings <ul><li>Warns against dubious programming habits
Some typical warnings </li><ul><li>Variables used only once
Using undefined variables
Writing to read-only file handles
And many more... </li></ul></ul>
Allowing Warnings <ul><li>Sometimes it's too much work to make code warnings clean
Turn off use warnings locally
Turn off specific warnings
{   no warnings 'deprecated';   # dodgy code ... }
See perldoc perllexwarn </li></ul>
References
Introducing References <ul><li>A reference is a bit like pointer in languages like C and Pascal (but better)
A reference is a unique way to refer to a variable.
A reference can always fit into a scalar variable
A reference looks like  SCALAR(0x20026730) </li></ul>
Creating References <ul><li>Put  in front of a variable name </li><ul><li>$scalar_ref = $scalar;
$array_ref = @array;
$hash_ref = hash; </li></ul><li>Can now treat it just like any other scalar </li><ul><li>$var = $scalar_ref;
$refs[0] = $array_ref;
$another_ref = $refs[0]; </li></ul></ul>
Creating References <ul><li>[ LIST ]  creates anonymous array and returns a reference
$aref = [ 'this', 'is', 'a', 'list']; $aref2 = [ @array ];
{ LIST }  creates anonymous hash and returns a reference
$href = { 1 => 'one', 2 => 'two' }; $href = { %hash }; </li></ul>
Creating References <ul><li>@arr = (1, 2, 3, 4); $aref1 = @arr; $aref2 = [ @arr ]; print &quot;$aref1
$aref2
&quot;;
Output ARRAY(0x20026800) ARRAY(0x2002bc00)
Second method creates a  copy  of the array </li></ul>
Using Array References <ul><li>Use  {$aref}  to get back an array that you have a reference to
Whole array
@array = @{$aref};
@rev = reverse @{$aref};
Single elements
$elem = ${$aref}[0];
${$aref}[0] = 'foo'; </li></ul>
Using Hash References <ul><li>Use  {$href}  to get back a hash that you have a reference to
Whole hash
%hash = %{$href};
@keys = keys %{$href};
Single elements
$elem = ${$href}{key};
${$href}{key} = 'foo'; </li></ul>
Using References <ul><li>Use arrow ( -> ) to access elements of arrays or hashes
Instead of  ${$aref}[0]  you can use $aref->[0]
Instead of  ${$href}{key}  you can use $href->{key} </li></ul>
Using References <ul><li>You can find out what a reference is referring to using ref
$aref = [ 1, 2, 3 ]; print ref $aref; # prints ARRAY
$href = { 1 => 'one',   2 => 'two' }; print ref $href; # prints HASH </li></ul>
Why Use References? <ul><li>Parameter passing
Complex data structures </li></ul>
Parameter Passing <ul><li>What does this do?
@arr1 = (1, 2, 3); @arr2 = (4, 5, 6); check_size(@arr1, @arr2); sub check_size {   my (@a1, @a2) = @_;   print @a1 == @a2 ...
Why Doesn't It Work? <ul><li>my (@a1, @a2) = @_;
Arrays are combined in  @_
All elements end up in  @a1
How do we fix it?
Pass references to the arrays </li></ul>
Another Attempt <ul><li>@arr1 = (1, 2, 3); @arr2 = (4, 5, 6); check_size(@arr1, @arr2); sub check_size {   my ($a1, $a2) =...
Complex Data Structures <ul><li>Another good use for references
Try to create a 2-D array
@arr_2d = ((1, 2, 3),   (4, 5, 6),   (7, 8, 9));
@arr_2d contains (1, 2, 3, 4, 5, 6, 7, 8, 9)
This is known a  array flattening </li></ul>
Complex Data Structures <ul><li>2D Array using references
@arr_2d = ([1, 2, 3],   [4, 5, 6],   [7, 8, 9]);
But how do you access individual elements?
$arr_2d[1]  is ref to array (4, 5, 6)
$arr_2d[1]->[1]  is element 5 </li></ul>
Complex Data Structures <ul><li>Another 2D Array
$arr_2d = [[1, 2, 3],   [4, 5, 6],   [7, 8, 9]];
Upcoming SlideShare
Loading in...5
×

Introduction to Perl - Day 2

22,407

Published on

Published in: Technology, Education
1 Comment
20 Likes
Statistics
Notes
No Downloads
Views
Total Views
22,407
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1,659
Comments
1
Likes
20
Embeds 0
No embeds

No notes for slide

Introduction to Perl - Day 2

  1. 1. Introduction to Perl Day 2 An Introduction to Perl Programming Dave Cross Magnum Solutions Ltd [email_address]
  2. 2. What We Will Cover <ul><li>Types of variable
  3. 3. Strict and warnings
  4. 4. References
  5. 5. Sorting
  6. 6. Reusable Code
  7. 7. Object Orientation </li></ul>
  8. 8. What We Will Cover <ul><li>Testing
  9. 9. Dates and Times
  10. 10. Templates
  11. 11. Databases
  12. 12. Further Information </li></ul>
  13. 13. Schedule <ul><li>09:30 – Begin
  14. 14. 11:00 – Coffee break (30 mins)
  15. 15. 13:00 – Lunch (90 mins)
  16. 16. 14:30 – Begin
  17. 17. 16:00 – Coffee break (30 mins)
  18. 18. 18:00 – End </li></ul>
  19. 19. Resources <ul><li>Slides available on-line </li><ul><li>http://mag-sol.com/train/public/2009/yapc </li></ul><li>Also see Slideshare </li><ul><li>http://www.slideshare.net/davorg/slideshows </li></ul><li>Get Satisfaction </li><ul><li>http://getsatisfaction.com/magnum </li></ul></ul>
  20. 20. Types of Variable
  21. 21. Types of Variable <ul><li>Perl variables are of two types
  22. 22. Important to know the difference
  23. 23. Lexical variables are created with my
  24. 24. Package variables are created by our
  25. 25. Lexical variables are associated with a code block
  26. 26. Package variables are associated with a package </li></ul>
  27. 27. Lexical Variables <ul><li>Created with my
  28. 28. my ($doctor, @timelords, %home_planets);
  29. 29. Live in a pad (associated with a block of code) </li><ul><li>Piece of code delimited by braces
  30. 30. Source file </li></ul><li>Only visible within enclosing block
  31. 31. &quot;Lexical&quot; because the scope is defined purely by the text </li></ul>
  32. 32. Packages <ul><li>All Perl code is associated with a package
  33. 33. A new package is created with package </li><ul><li>package MyPackage; </li></ul><li>Think of it as a namespace
  34. 34. Used to avoid name clashes with libraries
  35. 35. Default package is called main </li></ul>
  36. 36. Package Variables <ul><li>Live in a package's symbol table
  37. 37. Can be referred to using a fully qualified name </li><ul><li>$main::doctor
  38. 38. @Gallifrey::timelords </li></ul><li>Package name not required within own package
  39. 39. Can be seen from anywhere in the package (or anywhere at all when fully qualified) </li></ul>
  40. 40. Declaring Package Vars <ul><li>Can be predeclared with our
  41. 41. our ($doctor, @timelords, %home_planet);
  42. 42. Or (in older Perls) with use vars
  43. 43. use vars qw($doctor @timelords %home_planet); </li></ul>
  44. 44. Lexical or Package <ul><li>When to use lexical variables or package variables?
  45. 45. Simple answer </li><ul><li>Always use lexical variables </li></ul><li>More complete answer </li><ul><li>Always use lexical variables
  46. 46. Except for a tiny number of cases </li></ul><li>http://perl.plover.com/local.html </li></ul>
  47. 47. local <ul><li>You might see code that uses local
  48. 48. local $variable;
  49. 49. This doesn't do what you think it does
  50. 50. Badly named function
  51. 51. Doesn't create local variables
  52. 52. Creates a local copy of a package variable
  53. 53. Can be useful </li><ul><li>In a small number of cases </li></ul></ul>
  54. 54. local Example <ul><li>$/ is a package variable
  55. 55. It defines the record separator
  56. 56. You might want to change it
  57. 57. Always localise changes
  58. 58. { local $/ = “ ”; while (<FILE> ) { ... } } </li></ul>
  59. 59. Strict and Warnings
  60. 60. Coding Safety Net <ul><li>Perl can be a very loose programming language
  61. 61. Two features can minimise the dangers
  62. 62. use strict / use warnings
  63. 63. A good habit to get into
  64. 64. No serious Perl programmer codes without them </li></ul>
  65. 65. use strict <ul><li>Controls three things
  66. 66. use strict 'refs' – no symbolic references
  67. 67. use strict 'subs' – no barewords
  68. 68. use strict 'vars' – no undeclared variables
  69. 69. use strict – turn on all three at once
  70. 70. turn them off (carefully) with no strict </li></ul>
  71. 71. use strict 'refs' <ul><li>Prevents symbolic references
  72. 72. aka &quot;using a variable as another variable's name&quot;
  73. 73. $what = 'dalek'; $$what = 'Karn'; # sets $dalek to 'Karn'
  74. 74. What if 'dalek' came from user input?
  75. 75. People often think this is a cool feature
  76. 76. It isn't </li></ul>
  77. 77. use strict 'refs' (cont) <ul><li>Better to use a hash
  78. 78. $what = 'dalek'; $alien{$what} = 'Karn';
  79. 79. Self contained namespace
  80. 80. Less chance of clashes
  81. 81. More information (e.g. all keys) </li></ul>
  82. 82. use strict 'subs' <ul><li>No barewords
  83. 83. Bareword is a word with no other interpretation
  84. 84. e.g. word without $, @, %, &
  85. 85. Treated as a function call or a quoted string
  86. 86. $dalek = Karn;
  87. 87. May clash with future reserved words </li></ul>
  88. 88. use strict 'vars' <ul><li>Forces predeclaration of variable names
  89. 89. Prevents typos
  90. 90. Less like BASIC - more like Ada
  91. 91. Thinking about scope is good </li></ul>
  92. 92. use warnings <ul><li>Warns against dubious programming habits
  93. 93. Some typical warnings </li><ul><li>Variables used only once
  94. 94. Using undefined variables
  95. 95. Writing to read-only file handles
  96. 96. And many more... </li></ul></ul>
  97. 97. Allowing Warnings <ul><li>Sometimes it's too much work to make code warnings clean
  98. 98. Turn off use warnings locally
  99. 99. Turn off specific warnings
  100. 100. { no warnings 'deprecated'; # dodgy code ... }
  101. 101. See perldoc perllexwarn </li></ul>
  102. 102. References
  103. 103. Introducing References <ul><li>A reference is a bit like pointer in languages like C and Pascal (but better)
  104. 104. A reference is a unique way to refer to a variable.
  105. 105. A reference can always fit into a scalar variable
  106. 106. A reference looks like SCALAR(0x20026730) </li></ul>
  107. 107. Creating References <ul><li>Put in front of a variable name </li><ul><li>$scalar_ref = $scalar;
  108. 108. $array_ref = @array;
  109. 109. $hash_ref = hash; </li></ul><li>Can now treat it just like any other scalar </li><ul><li>$var = $scalar_ref;
  110. 110. $refs[0] = $array_ref;
  111. 111. $another_ref = $refs[0]; </li></ul></ul>
  112. 112. Creating References <ul><li>[ LIST ] creates anonymous array and returns a reference
  113. 113. $aref = [ 'this', 'is', 'a', 'list']; $aref2 = [ @array ];
  114. 114. { LIST } creates anonymous hash and returns a reference
  115. 115. $href = { 1 => 'one', 2 => 'two' }; $href = { %hash }; </li></ul>
  116. 116. Creating References <ul><li>@arr = (1, 2, 3, 4); $aref1 = @arr; $aref2 = [ @arr ]; print &quot;$aref1 $aref2 &quot;;
  117. 117. Output ARRAY(0x20026800) ARRAY(0x2002bc00)
  118. 118. Second method creates a copy of the array </li></ul>
  119. 119. Using Array References <ul><li>Use {$aref} to get back an array that you have a reference to
  120. 120. Whole array
  121. 121. @array = @{$aref};
  122. 122. @rev = reverse @{$aref};
  123. 123. Single elements
  124. 124. $elem = ${$aref}[0];
  125. 125. ${$aref}[0] = 'foo'; </li></ul>
  126. 126. Using Hash References <ul><li>Use {$href} to get back a hash that you have a reference to
  127. 127. Whole hash
  128. 128. %hash = %{$href};
  129. 129. @keys = keys %{$href};
  130. 130. Single elements
  131. 131. $elem = ${$href}{key};
  132. 132. ${$href}{key} = 'foo'; </li></ul>
  133. 133. Using References <ul><li>Use arrow ( -> ) to access elements of arrays or hashes
  134. 134. Instead of ${$aref}[0] you can use $aref->[0]
  135. 135. Instead of ${$href}{key} you can use $href->{key} </li></ul>
  136. 136. Using References <ul><li>You can find out what a reference is referring to using ref
  137. 137. $aref = [ 1, 2, 3 ]; print ref $aref; # prints ARRAY
  138. 138. $href = { 1 => 'one', 2 => 'two' }; print ref $href; # prints HASH </li></ul>
  139. 139. Why Use References? <ul><li>Parameter passing
  140. 140. Complex data structures </li></ul>
  141. 141. Parameter Passing <ul><li>What does this do?
  142. 142. @arr1 = (1, 2, 3); @arr2 = (4, 5, 6); check_size(@arr1, @arr2); sub check_size { my (@a1, @a2) = @_; print @a1 == @a2 ? 'Yes' : 'No'; } </li></ul>
  143. 143. Why Doesn't It Work? <ul><li>my (@a1, @a2) = @_;
  144. 144. Arrays are combined in @_
  145. 145. All elements end up in @a1
  146. 146. How do we fix it?
  147. 147. Pass references to the arrays </li></ul>
  148. 148. Another Attempt <ul><li>@arr1 = (1, 2, 3); @arr2 = (4, 5, 6); check_size(@arr1, @arr2); sub check_size { my ($a1, $a2) = @_; print @$a1 == @$a2 ? 'Yes' : 'No'; } </li></ul>
  149. 149. Complex Data Structures <ul><li>Another good use for references
  150. 150. Try to create a 2-D array
  151. 151. @arr_2d = ((1, 2, 3), (4, 5, 6), (7, 8, 9));
  152. 152. @arr_2d contains (1, 2, 3, 4, 5, 6, 7, 8, 9)
  153. 153. This is known a array flattening </li></ul>
  154. 154. Complex Data Structures <ul><li>2D Array using references
  155. 155. @arr_2d = ([1, 2, 3], [4, 5, 6], [7, 8, 9]);
  156. 156. But how do you access individual elements?
  157. 157. $arr_2d[1] is ref to array (4, 5, 6)
  158. 158. $arr_2d[1]->[1] is element 5 </li></ul>
  159. 159. Complex Data Structures <ul><li>Another 2D Array
  160. 160. $arr_2d = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
  161. 161. $arr_2d->[1] is ref to array (4, 5, 6)
  162. 162. $arr_2d->[1]->[1] is element 5
  163. 163. Can omit intermediate arrows
  164. 164. $arr_2d->[1][1] </li></ul>
  165. 165. More Data Structures <ul><li>Imagine the following data file
  166. 166. Jones,Martha,UNIT Harkness,Jack,Torchwood Smith,Sarah Jane,Journalist
  167. 167. What would be a good data structure?
  168. 168. Hash for each record
  169. 169. Array of records
  170. 170. Array of hashes </li></ul>
  171. 171. More Data Structures <ul><li>Building an array of hashes
  172. 172. my @records; my @cols = ('s_name', 'f_name', 'job'); while (<FILE>) { chomp; my %rec; @rec{@cols} = split /,/; push @records, rec; } </li></ul>
  173. 173. Using an Array of Hashes foreach (@records) { print &quot;$_->{f_name} &quot;, &quot;$_->{s_name} &quot;. &quot;is a $_->{job} &quot;; }
  174. 174. Complex Data Structures <ul><li>Many more possibilities </li><ul><li>Hash of hashes
  175. 175. Hash of lists
  176. 176. Multiple levels (list of hash of hash, etc.) </li></ul><li>Lots of examples in “perldoc perldsc” (the data structures cookbook) </li></ul>
  177. 177. Sorting
  178. 178. Sorting <ul><li>Perl has a sort function that takes a list and sorts it
  179. 179. @sorted = sort @array;
  180. 180. Note that it does not sort the list in place
  181. 181. @array = sort @array; </li></ul>
  182. 182. Sort Order <ul><li>The default sort order is ASCII
  183. 183. @chars = sort 'e', 'b', 'a', 'd', 'c'; # @chars has ('a', 'b', 'c', 'd', 'e')
  184. 184. This can sometimes give strange results
  185. 185. @chars = sort 'E', 'b', 'a', 'D', 'c'; # @chars has ('D', 'E', 'a', 'b', 'c')
  186. 186. @nums = sort 1 .. 10; # @nums has (1, 10, 2, 3, 4, # 5, 6, 7, 8, 9) </li></ul>
  187. 187. Sorting Blocks <ul><li>Can add a &quot;sorting block&quot; to customise sort order
  188. 188. @nums = sort { $a <=> $b } 1 .. 10;
  189. 189. Perl puts two of the values from the list into $a and $b
  190. 190. Block compares values and returns -1, 0 or 1
  191. 191. <=> does this for numbers ( cmp for strings) </li></ul>
  192. 192. Sort Examples <ul><li>Other simple sort examples
  193. 193. sort { $b cmp $a } @words
  194. 194. sort { lc $a cmp lc $b } @words
  195. 195. sort { substr($a, 4) cmp substr($b, 4) } @lines </li></ul>
  196. 196. Sorting Subroutines <ul><li>Can also use a subroutine name in place of a code block
  197. 197. @words = sort dictionary @words; sub dictionary { # Don't change $a and $b my ($A, $B) = ($a, $b); $A =~ s/W+//g; $B =~ s/W+//g; $A cmp $B; } </li></ul>
  198. 198. Sorting Names <ul><li>my @names = ('Rose Tyler', 'Martha Jones', 'Donna Noble', 'Amy Pond'); @names = sort sort_names @names;
  199. 199. Need to write sort_names so that it sorts on surname and then forename. </li></ul>
  200. 200. Sorting Names (cont) <ul><li>sub sort_names { my @a = split /s/, $a; my @b = split /s/, $b; return $a[1] cmp $b[1] or $a[0] cmp $b[1]; } </li></ul>
  201. 201. More Complex Sorts <ul><li>sub sort_names { my @a = split /s/, $a; my @b = split /s/, $b; return $a[1] cmp $b[1] or $a[0] cmp $b[0]; }
  202. 202. Can be inefficient on large amounts of data
  203. 203. Multiple splits on the same data </li></ul>
  204. 204. More Efficient Sorts <ul><li>Split each row only once
  205. 205. @split = map { [ split ] } @names;
  206. 206. Do the comparison
  207. 207. @sort = sort { $a->[1] cmp $b->[1] or $a->[0] cmp $b->[0] } @split;
  208. 208. Join the data together
  209. 209. @names = map { join ' ', @$_ } @sort; </li></ul>
  210. 210. Put It All Together <ul><li>Can rewrite this as
  211. 211. @names = map { join ' ', @$_ } sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] } map { [ split ] } @names;
  212. 212. All functions work on the output from the previous function in the chain </li></ul>
  213. 213. Schwartzian Transform <ul><li>@data_out = map { $_->[1] } sort { $a->[0] cmp $a->[0] } map { [func($_), $_] } @data_in;
  214. 214. Old Lisp trick
  215. 215. Named after Randal Schwartz </li></ul>
  216. 216. Reusable Code
  217. 217. Why Write Modules? <ul><li>Code reuse
  218. 218. Prevent reinventing the wheel
  219. 219. Easier to share across projects
  220. 220. Better design, more generic </li></ul>
  221. 221. Basic Module <ul><li>use strict; use warnings; package MyModule; use Exporter; our @ISA = ('Exporter'); our @EXPORT = ('my_sub'); sub my_sub { print &quot;This is my_sub &quot;; } 1; </li></ul>
  222. 222. Using MyModule.pm <ul><li>use MyModule; # my_sub is now available # for use within your # program my_sub(); # Prints &quot;This is my_sub()&quot; </li></ul>
  223. 223. Explaining MyModule.pm <ul><li>Much of MyModule.pm is concerned with exporting subroutine names
  224. 224. Subroutine full name </li><ul><li>MyModule::my_sub() </li></ul><li>Exporting abbreviates that </li><ul><li>my_sub() </li></ul></ul>
  225. 225. Packages Revisited <ul><li>Every subroutine lives in a package
  226. 226. The default package is main
  227. 227. New packages are introduced with the package keyword
  228. 228. A subroutine's full name is package::name
  229. 229. Package name can be omitted from within same package
  230. 230. Like family names </li></ul>
  231. 231. Using Exporter <ul><li>The module Exporter.pm handles the export of subroutine (and variable) names
  232. 232. Exporter.pm defines a subroutine called import
  233. 233. import is automatically called whenever a module is used
  234. 234. import puts references to our subroutines into our caller's symbol table </li></ul>
  235. 235. How Exporter Works <ul><li>How does MyModule use Exporter's import subroutine?
  236. 236. We make use of inheritance
  237. 237. Inheritance is defined using the @ISA array
  238. 238. If we call a subroutine that doesn't exist in our module, then the modules in @ISA are also checked
  239. 239. Therefore Exporter::import is called </li></ul>
  240. 240. Exporting Symbols <ul><li>How does import know which subroutines to export?
  241. 241. Exports are defined in @EXPORT or @EXPORT_OK
  242. 242. Automatic exports are defined in @EXPORT
  243. 243. Optional exports are defined in @EXPORT_OK </li></ul>
  244. 244. Exporting Symbol Sets <ul><li>You can define sets of exports in %EXPORT_TAGS
  245. 245. Key is set name
  246. 246. Value is reference to an array of names
  247. 247. our %EXPORT_TAGS = (advanced => [ qw( my_sub my_other_sub ) ]; use MyModule qw(:advanced); my_sub(); my_other_sub(); </li></ul>
  248. 248. Why Use @EXPORT_OK? <ul><li>Give your users the choice of which subroutines to import
  249. 249. Less chances of name clashes
  250. 250. Use @EXPORT_OK in preference to @EXPORT
  251. 251. Document the exported names and sets </li></ul>
  252. 252. Exporting Variables <ul><li>You can also export variables
  253. 253. @EXPORT_OK = qw($scalar, @array, %hash);
  254. 254. Can be part of export sets
  255. 255. Any variables you export must be package variables </li></ul>
  256. 256. Writing Modules The Easy Way <ul><li>A lot of module code is similar
  257. 257. Don't write the boilerplate yourself
  258. 258. Copy from an existing module
  259. 259. Or look at Module::Starter </li></ul>
  260. 260. Object Orientation
  261. 261. OO Programming <ul><li>Traditional programming has subroutines acting on methods
  262. 262. OO inverts this
  263. 263. Classes contain methods which define their actions
  264. 264. Objects are instances of classes
  265. 265. Perl has an OO system bolted on
  266. 266. Best of both worlds </li></ul>
  267. 267. Object Oriented Perl <ul><li>An Object is just a module that obeys certain extra rules
  268. 268. Three rules of Perl objects </li><ul><li>A Class is a package
  269. 269. An Object is a reference (usually to a hash)
  270. 270. A Method is a subroutine </li></ul><li>bless tells a reference what kind of object it is </li></ul>
  271. 271. A Simple Object <ul><li>package MyObject; sub new { my $class = shift; my $name = shift; my $self = { name => $name }; return bless $self, $class; } </li></ul>
  272. 272. A Simple Object (cont) <ul><li>sub get_name { my $self = shift; return $self->{name}; } sub set_name { my $self = shift; $self->{name} = shift; } 1; </li></ul>
  273. 273. Using MyObject.pm <ul><li>use MyObject; my $obj = MyObject->new('Dave'); print $obj->get_name; # prints 'Dave' $obj->set_name('David'); print $obj->get_name; # prints 'David' </li></ul>
  274. 274. Moose <ul><li>Easier OO Perl
  275. 275. Moose is on CPAN
  276. 276. Based on Perl 6 OO
  277. 277. Well worth investigating </li></ul>
  278. 278. Moose Example <ul><li>package MyModule; use Moose; has name => (is => 'rw', isa => 'Str', required => 1);
  279. 279. 1; </li></ul>
  280. 280. Further Information <ul><li>perldoc perlboot
  281. 281. perldoc perltoot
  282. 282. perldoc perlobj
  283. 283. perldoc perlbot
  284. 284. perldoc Moose (if it is installed)
  285. 285. Object Oriented Perl (Conway) </li></ul>
  286. 286. Testing
  287. 287. Testing <ul><li>Never program without a safety net
  288. 288. Does your code do what it is supposed to do?
  289. 289. Will your code continue to do what it is supposed to do?
  290. 290. Write unit tests
  291. 291. Run those tests all the time </li></ul>
  292. 292. When to Run Tests <ul><li>As often as possible
  293. 293. Before you add a feature
  294. 294. After you have added a feature
  295. 295. Before checking in code
  296. 296. Before releasing code
  297. 297. Constantly, automaticall y </li></ul>
  298. 298. Testing in Perl <ul><li>Perl makes it easy to write test suites
  299. 299. A lot of work in this area over the last eight years
  300. 300. Test::Simple and Test::More included in Perl distribution
  301. 301. Many more testing modules on CPAN </li></ul>
  302. 302. Simple Test Program <ul><li>use Test::More tests => 4; BEGIN { use_ok('My::Object'); } ok(my $obj = My::Object->new); isa_ok($obj, 'My::Object'); $obj->set_foo('Foo'); is($obj->get_foo, 'Foo'); </li></ul>
  303. 303. Simple Test Output <ul><li>$ prove -v test.t test.... 1..4 ok 1 - use My::Object; ok 2 ok 3 - The object isa My::Object ok 4 ok All tests successful. Files=1, Tests=4, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.05 cusr 0.00 csys = 0.07 CPU) Result: PASS </li></ul>
  304. 304. Adding Test Names <ul><li>use Test::More tests => 4; BEGIN { use_ok('My::Object'); } ok(my $obj = My::Object->new, 'Got an object'); isa_ok($obj, 'My::Object'); $obj->set_foo('Foo'); is($obj->get_foo, 'Foo', 'The foo is &quot;Foo&quot;'); </li></ul>
  305. 305. Output With Names <ul><li>$ prove -v test2.t test2.... 1..4 ok 1 - use My::Object; ok 2 - got an object ok 3 - The object isa My::Object ok 4 - The foo is &quot;Foo&quot; ok All tests successful. Files=1, Tests=4, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.05 cusr 0.00 csys = 0.07 CPU) Result: PASS </li></ul>
  306. 306. Using prove <ul><li>prove is a command line tool for running tests
  307. 307. Runs given tests using Test::Harness
  308. 308. Comes with the Perl distribution
  309. 309. Command line options </li><ul><li>-v verbose output
  310. 310. -r recurse
  311. 311. -s shuffle tests
  312. 312. Many more </li></ul></ul>
  313. 313. Test Anything Protocol <ul><li>Perl tests have been spitting out “ok 1” and not “ok 2” for years
  314. 314. Now this ad-hoc format has a definition and a name
  315. 315. The Test Anything Protocol (TAP)
  316. 316. See Test::Harness::TAP (documentation module) and TAP::Parser </li></ul>
  317. 317. TAP Output <ul><li>More possibilities for test output </li><ul><li>TAP::Harness::Color
  318. 318. Test::TAP::HTMLMatrix </li></ul><li>Make sense of your test results </li></ul>
  319. 319. More Testing Modules <ul><li>Dozens of testing modules on CPAN
  320. 320. Some of my favourites
  321. 321. Test::File
  322. 322. Test::Exception, Test::Warn
  323. 323. Test::Differences
  324. 324. Test::XML (includes Test::XML::XPath) </li></ul>
  325. 325. Writing Test Modules <ul><li>These test modules all work together
  326. 326. Built using Test::Builder
  327. 327. Ensures that test modules all use the same framework
  328. 328. Use it as the basis of your own Test::* modules
  329. 329. Who tests the testers?
  330. 330. Test your Test::Builder test modules with Test::Builder::Tester </li></ul>
  331. 331. How Good Are Your Tests? <ul><li>How much of your code is exercised by your tests?
  332. 332. Devel::Cover can help you to find out
  333. 333. Deep internal magic
  334. 334. Draws pretty charts </li><ul><li>HARNESS_PERL_SWITCHES= -MDevel::Cover make test
  335. 335. cover </li></ul></ul>
  336. 336. Devel::Cover Output
  337. 337. Devel::Cover Output
  338. 338. Devel::Cover Output
  339. 339. Alternative Test Paradigms <ul><li>Not everyone likes the Perl testing framework
  340. 340. Other frameworks are available
  341. 341. Test::Class </li><ul><li>xUnit style framework </li></ul><li>Test::FIT </li><ul><li>Framework for Interactive Testing
  342. 342. http://fit.c2.com </li></ul></ul>
  343. 343. More Information <ul><li>Perl Testing: A Developer's Notebook (Ian Langworth & chromatic)
  344. 344. perldoc Test::Tutorial
  345. 345. perldoc Test::Simple
  346. 346. perldoc Test::More
  347. 347. perldoc Test::Builder
  348. 348. etc... </li></ul>
  349. 349. Dates and Times
  350. 350. Dates & Times <ul><li>Perl has built-in functions to handle dates and times
  351. 351. Flexible but confusing
  352. 352. time – seconds since 1st Jan 1970
  353. 353. localtime – convert to human-readable
  354. 354. timelocal (in Time::Local) – inverse of localtime
  355. 355. strftime (in POSIX) – formatting dates and times </li></ul>
  356. 356. Dates & Times on CPAN <ul><li>Look to CPAN for a better answer
  357. 357. Dozens of date/time modules on CPAN
  358. 358. Date::Manip is almost never what you want
  359. 359. Date::Calc, Date::Parse, Class::Date, Date::Simple, etc
  360. 360. Which one do you choose? </li></ul>
  361. 361. Perl DateTime Project <ul><li>http://datetime.perl.org/
  362. 362. &quot;The DateTime family of modules present a unified way to handle dates and times in Perl&quot;
  363. 363. &quot;unified&quot; is good
  364. 364. Dozens of modules that work together in a consistent fashion </li></ul>
  365. 365. Using DateTime <ul><li>use DateTime; my $dt = DateTime->now; say $dt; # 2009-08-02T15:06:07 say $dt->dmy, &quot; &quot;; # 2009-08-02 say $dt->hms, &quot; &quot;; # 15:06:07 </li></ul>
  366. 366. Using DateTime <ul><li>use DateTime; my $dt = DateTime->new(year => 2009, month => 8, day => 2); say $dt->ymd('/'), &quot; &quot;; # 2009/08/02 say $dt->month; # 8 say $dt->month_name; # August </li></ul>
  367. 367. Arithmetic <ul><li>A DateTime object is a point in time
  368. 368. For date arithmetic you need a duration
  369. 369. Number of years, weeks, days, etc </li></ul>
  370. 370. Arithmetic <ul><li>use DateTime; my $dt = DateTime->new(year => 2009, month => 8, day => 2); my $two_weeks = DateTime::Duration->new(weeks => 2); $dt += $two_weeks; say $dt; # 2009-02-16T00:00:00 </li></ul>
  371. 371. Formatting Output <ul><li>use DateTime; my $dt = DateTime->new(year => 2009, month => 2, day => 26); say $dt->strftime('%A, %d %B %Y'); # Tuesday, 26 February 2009
  372. 372. Control input format with DateTime::Format::Strptime </li></ul>
  373. 373. Parsing & Formatting <ul><li>Ready made parsers and formatters for popular date and time formats
  374. 374. DateTime::Format::HTTP
  375. 375. DateTime::Format::MySQL
  376. 376. DateTime::Format::Excel
  377. 377. DateTime::Format::Baby </li><ul><li>the big hand is on... </li></ul></ul>
  378. 378. Alternative Calendars <ul><li>Handling non-standard calendars
  379. 379. DateTime::Calendar::Julian
  380. 380. DateTime::Calendar::Hebrew
  381. 381. DateTime::Calendar::Mayan
  382. 382. DateTime::Fiction::JRRTolkien::Shire </li></ul>
  383. 383. Calendar Examples <ul><li>use DateTime::Calendar::Mayan; my $dt = DateTime::Calendar::Mayan->now; say $dt->date; # 12.19.16.9.15
  384. 384. use DateTime::Fiction::JRRTolkien::Shire my $dt = DateTime::Fiction::JRRTolkien::Shire->now; say $dt->on_date; # Trewsday 1 Wedmath 7473 </li></ul>
  385. 385. Templates
  386. 386. Templates <ul><li>Many people use templates to produce web pages
  387. 387. Advantages are well known
  388. 388. Standard look and feel (static/dynamic)
  389. 389. Reusable components
  390. 390. Separation of code logic from display logic
  391. 391. Different skill-sets (HTML vs Perl) </li></ul>
  392. 392. Non-Web Templates <ul><li>The same advantages apply to non-web areas
  393. 393. Reports
  394. 394. Business documents
  395. 395. Configuration files
  396. 396. Anywhere you produce output </li></ul>
  397. 397. DIY Templating <ul><li>Must be easy - so many people do it
  398. 398. See perlfaq4
  399. 399. “How can I expand variables in text strings?” </li></ul>
  400. 400. DIY Templating <ul><li>$text = 'this has a $foo in it and a $bar'; %user_defs = ( foo => 23, bar => 19, ); $text =~ s/$(w+)/$user_defs{$1}/g;
  401. 401. Don't do that </li></ul>
  402. 402. Templating Options <ul><li>Dozens of template modules on CPAN
  403. 403. Text::Template, HTML::Template, Mason, Template Toolkit
  404. 404. Many, many more
  405. 405. Questions to consider </li><ul><li>HTML only?
  406. 406. Template language </li></ul><li>I choose the Template Toolkit </li></ul>
  407. 407. Template Toolkit <ul><li>http://tt2.org/
  408. 408. Very powerful
  409. 409. Both web and non-web
  410. 410. Simple template language
  411. 411. Plugins give access to much of CPAN
  412. 412. Can use Perl code if you want </li><ul><li>But don't do that </li></ul></ul>
  413. 413. Good Book Too!
  414. 414. The Template Equation <ul><li>Data + Template = Output
  415. 415. Data + Alternative Template = Alternative Output
  416. 416. Different views of the same data
  417. 417. Only the template changes </li></ul>
  418. 418. Simple TT Example <ul><li>use Template; use My::Object; my ($id, $format) = @ARGV; $format ||= 'html'; my $obj = My::Object->new($id) or die; my $tt = Template->new; $tt->process(&quot;$format.tt&quot;, { obj => $obj }, &quot;$id.$format&quot;) or die $tt->error; </li></ul>
  419. 419. html.tt <ul><li><html> <head> <title>[% obj.name %]</title> </head> <body> <h1>[% obj.name %]<h1> <p><img src=“[% obj.img %]” /><br /> [% obj.desc %]</p> <ul> [% FOREACH child IN obj.children -%] <li>[% child.name %]</li> [% END %] </body> </html> </li></ul>
  420. 420. text.tt <ul><li>[% obj.name | upper %] Image: [% obj.img %] [% obj.desc %] [% FOREACH child IN obj.children -%] * [% child.name %] [% END %] </li></ul>
  421. 421. Adding New Formats <ul><li>No new code required
  422. 422. Just add new output template
  423. 423. Perl programmer need not be involved </li></ul>
  424. 424. Equation Revisited <ul><li>Data + Template = Output </li><ul><li>Template Toolkit </li></ul><li>Template + Output = Data </li><ul><li>Template::Extract </li></ul><li>Data + Output = Template </li><ul><li>Template::Generate </li></ul></ul>
  425. 425. Databases
  426. 426. Databases <ul><li>A large proportion of applications need to talk to databases
  427. 427. Perl has tools to make this as simple as possible
  428. 428. DBI is the basis for all modern Perl database access
  429. 429. You should be using DBI </li><ul><li>or something based on DBI </li></ul></ul>
  430. 430. How DBI Works <ul><li>Program uses DBI.pm
  431. 431. Create a connection to a particular type of database
  432. 432. DBD module gets loaded
  433. 433. DBD translates from DBI API to database specific calls
  434. 434. DBD translates returned data into Perl data stuctures </li></ul>
  435. 435. Connecting to a DB <ul><li>use DBI; my $dbh = DBI->connect( &quot;dbi:mysql:$some_stuff&quot;, $user, $pass );
  436. 436. “mysql” is the name of the DBD </li><ul><li>DBD::mysql </li></ul><li>In theory you can port a program to another database
  437. 437. Just change the connection line </li></ul>
  438. 438. Selecting Data <ul><li>Prepare the SQL statement
  439. 439. my $sth = $dbh->prepare( 'select name, genre from artist' );
  440. 440. my $sth = $dbh->prepare( &quot;select title, from song where artist = '$id'&quot;);
  441. 441. Check return values (syntax errors) </li></ul>
  442. 442. Selecting Data (cont) <ul><li>Execute the statement
  443. 443. $sth->execute
  444. 444. Still need to check for errors </li></ul>
  445. 445. Selecting Data (cont) <ul><li>Fetch the returned data
  446. 446. while (my @row = $sth->fetchrow_array){ print &quot;@row &quot;; }
  447. 447. Fields are returned in the same order as they are defined in the query </li></ul>
  448. 448. Other Select Functions <ul><li>Other fetch methods are available: </li><ul><li>fetchrow_arrayref
  449. 449. fetchrow_hashref (keys are column names)
  450. 450. fetchall_arrayref
  451. 451. fetch (alias for fetchrow_arrayref) </li></ul><li>Many more added each week </li></ul>
  452. 452. Some Caveats <ul><li>If you're using a fetch method that returns an array </li><ul><li>Never use &quot;select *&quot;
  453. 453. For (hopefully) obvious reasons </li></ul><li>If you're using a fetch method that returns a hash </li><ul><li>Ensure all your columns have (unique) names
  454. 454. For (hopefully) obvious reasons </li></ul></ul>
  455. 455. Insert, Update & Delete <ul><li>Statements that don't return data can be executed the same way
  456. 456. my $sql = &quot;update table1 set col1 = '$val' where id_col = $id&quot;; my $sth = $dbh->prepare($sql); $sth->execute;
  457. 457. But there's a shortcut
  458. 458. $rows = $dbh->do($sql); </li></ul>
  459. 459. Multiple Insertions <ul><li>while (<FILE>) { chomp; my @data = split; my $sql = &quot;insert into tab values ($data[0], $data[1], $data[2]&quot;); $dbh->do($sql); }
  460. 460. Recompiles the SQL every time
  461. 461. Very inefficient </li></ul>
  462. 462. Binding Data <ul><li>Prepare statement once, use many times
  463. 463. my $sql = &quot;insert into tab values (?, ?, ?)&quot;; my $sth = $dbh->prepare($sql); while (<FILE>) { my @data = split; bind_param(1, $data[0]); bind_param(2, $data[1]); bind_param(3, $data[2]); $sth->execute; }
  464. 464. Bonus - binding handles quoting for you </li></ul>
  465. 465. Binding Data (cont) <ul><li>Even easier – extra parameters to execute
  466. 466. my $sql = &quot;insert into tab values (?, ?, ?)&quot;; my $sth = $dbh->prepare($sql); while (<FILE>) { chomp; my @data = split; $sth->execute(@data); } </li></ul>
  467. 467. Unnamed Placeholders <ul><li>Having unnamed placeholders can get confusing
  468. 468. my $sql = 'insert into big_table values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
  469. 469. Good chance of getting the variables in the wrong order
  470. 470. By the way - there's a basic maintainability error in that SQL </li></ul>
  471. 471. Bind By Name <ul><li>my $sql = 'insert into big_table (id, code, name, addr, email, url, ... ) values (:id, :code, :name, :addr, :email, :url, ... ); my $sth = $sql->prepare($sql); $sth->bind_param(':id', $id); $sth->bind_param(':code', $code); # etc $sth->execute; </li></ul>
  472. 472. Even Easier Binding <ul><li>Store your data in a hash
  473. 473. my %data = (id => 42, code => 'H2G2', ... ); # and later... foreach my $col (keys %data) { $sth->bind_param(&quot;:$col&quot;, $data{$col}; } </li></ul>
  474. 474. Downsides <ul><li>Many DBDs don't support it
  475. 475. Which is a bit of a bugger
  476. 476. Oracle does
  477. 477. So does PostgreSQL (tho' the docs discourage its use)
  478. 478. Check your DBD documentation
  479. 479. Email your friendly neighbourhood DBD author </li></ul>
  480. 480. Some Tips <ul><li>Make your life as easy as possible
  481. 481. Don't hard-code connection data </li><ul><li>Config file, command line options, environment variables </li></ul><li>Send all of your data access through one function
  482. 482. Store SQL queries externally and reference them by name
  483. 483. Use named bind parameters if you can </li></ul>
  484. 484. Sample Code <ul><li>my $dbh; sub run_sql { my ($sql_statement, %args) = @_; my $sql = get_sql($sql_statement); $dbh = get_dbh() unless $dbh; my $sth = $dbh->prepare($sql); foreach my $col (keys %args) { $sth->bind_param(&quot;:$col&quot;, $args{$col}); } return $sth->execute; } </li></ul>
  485. 485. Not Writing SQL <ul><li>Writing SQL is boring
  486. 486. It's often similar </li><ul><li>Select the id and name from this table
  487. 487. Select all the details of this row
  488. 488. Select something about related tables
  489. 489. Update this row with these values
  490. 490. Insert a new record with these values
  491. 491. Delete this record </li></ul><li>Must be a better way </li></ul>
  492. 492. Object Relational Mapping <ul><li>Mapping database relations into objects
  493. 493. Tables (relations) map onto classes
  494. 494. Rows (tuples) map onto objects
  495. 495. Columns (attributes) map onto attributes
  496. 496. Don't write SQL </li></ul>
  497. 497. Replacing SQL <ul><li>Instead of
  498. 498. SELECT * FROM my_table WHERE my_id = 10
  499. 499. and then dealing with the prepare/execute/fetch code </li></ul>
  500. 500. Replacing SQL <ul><li>We can write
  501. 501. use My::Object; # warning! not a real orm my $obj = My::Object->retrieve(10) $obj->name('A New Name'); $obj->save;
  502. 502. Or something similar </li></ul>
  503. 503. ORM on CPAN <ul><li>Very many ORMs on CPAN
  504. 504. Tangram
  505. 505. Alzabo
  506. 506. Class::DBI
  507. 507. DBIx::Class </li><ul><li>The current favourite
  508. 508. Highly recommended </li></ul></ul>
  509. 509. Further Information <ul><li>perldoc DBI
  510. 510. perldoc DBD::* </li><ul><li>DBD::mysql
  511. 511. DBD::Oracle
  512. 512. Etc... </li></ul><li>perldoc DBIx::Class </li></ul>
  513. 513. Further Information
  514. 514. Perl Websites <ul><li>Perl Home Page </li><ul><li>http://www.perl.org </li></ul><li>CPAN </li><ul><li>http://www.cpan.org
  515. 515. http://search.cpan.org </li></ul><li>Perl Mongers (Perl User Groups)‏ </li><ul><li>http://www.pm.org
  516. 516. http://london.pm.org </li></ul></ul>
  517. 517. Perl Websites <ul><li>use.perl – Perl News & Journals </li><ul><li>http://use.perl.org/ </li></ul><li>Perl Monks – Perl Help and Advice </li><ul><li>http://perlmonks.org/ </li></ul><li>Perl Documentation Online </li><ul><li>http://perldoc.perl.org/ </li></ul></ul>
  518. 518. Perl Conferences <ul><li>The Perl Conference (part of the Open Source Convention)‏ </li><ul><li>July 20-24 2009, San Jose, California
  519. 519. http://conferences.oreilly.com/oscon </li></ul><li>Yet Another Perl Conference </li><ul><li>August 3-5 2009, Lisbon, Portugal
  520. 520. http://www.yapceurope.org </li></ul></ul>
  521. 521. Perl Conferences <ul><li>Other YAPCs </li><ul><li>Pittsburgh, Pennsylvania
  522. 522. Brazil
  523. 523. Tokyo </li></ul><li>OSDC </li><ul><li>Israel
  524. 524. Australia </li></ul></ul>
  525. 525. Perl Workshops <ul><li>One-day grassroots conferences
  526. 526. UK, Germany, Israel, Pittsburgh, Nordic, Netherlands, France, Belgium, Russia, Minnesota, Austria
  527. 527. Perl Review Calendar </li><ul><li>www.theperlreview.com/community_calendar </li></ul></ul>
  528. 528. Perl Mailing Lists <ul><li>See http://lists.perl.org for full details </li><ul><li>Perl Mongers (social discussion)‏
  529. 529. CGI
  530. 530. DBI
  531. 531. XML
  532. 532. Beginners
  533. 533. Advocacy
  534. 534. Fun with Perl </li></ul></ul>
  535. 535. Perl Books <ul><li>Books for learning Perl </li><ul><li>Learning Perl (5th ed - June 2008) Schwartz, Phoenix & foy (O'Reilly)‏
  536. 536. Intermediate Perl Schwartz, foy & Phoenix (O'Reilly)‏
  537. 537. Beginning Perl Cozens (Wrox) http://www.perl.org/books/beginning-perl/ </li></ul></ul>
  538. 538. Perl Books <ul><li>Books you should have access to </li><ul><li>Programming Perl (3rd edition) Wall, Christiansen & Orwant (O'Reilly)‏
  539. 539. The Perl Cookbook (2nd edition) Christiansen & Torkington (O'Reilly)‏
  540. 540. Perl Best Practices Conway (O'Reilly)‏
  541. 541. Perl in a Nutshell Siever, Spainhour & Patwardhan (O'Reilly)‏ </li></ul></ul>
  542. 542. Perl Books <ul><li>Books you should probably look at </li><ul><li>Mastering Regular Expressions Friedl (O'Reilly)‏
  543. 543. Data Munging with Perl Cross (Manning)‏
  544. 544. Advanced Perl Programming Cozens (O'Reilly)‏
  545. 545. Perl Medic Scott (Addison Wesley) </li></ul></ul>
  546. 546. Perl Books <ul><li>Specialised Perl books </li><ul><li>Object Oriented Perl Conway (Manning)‏
  547. 547. Programming the Perl DBI Descartes & Bunce (O'Reilly)‏
  548. 548. Writing CGI Applications with Perl Meltzer & Michelski (Addison Wesley)‏
  549. 549. Practical mod_perl Bekman & Cholet (O'Reilly)‏
  550. 550. Perl Template Toolkit Chamberlain, Cross & Wardley </li></ul></ul>
  551. 551. Perl Magazines <ul><li>The Perl Review </li><ul><li>http://www.theperlreview.com </li></ul></ul>
  552. 552. That's All Folks <ul><li>Any Questions? </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×