Perl Presentation


Published on

The Perl Presentation - also talks about writing simple TWiki Plugin

Published in: Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Perl Presentation

    1. 1. Perl Sopan Shewale, [email_address]
    2. 2. Hello World – First Program $ cat #!/usr/bin/perl print "Welcome to the world of Perl Programming ! "; $ chmod +x $ ./ Welcome to the world of Perl Programming ! $ perl Welcome to the world of Perl Programming ! Make it executable Execute it Another Way to Execute
    3. 3. Another Simple Example – Taking input from user [sopan@ps3724 tutorial]$ cat #!/usr/bin/perl my $user; print &quot;Please write your name:&quot;; $user = <STDIN>; print &quot;Welcome to the world of perl, You are : $user &quot;;
    4. 4. Simple example – way to execute external command [sopan@ps3724 tutorial]$ cat #!/usr/bin/perl print &quot;Method1: &quot;; my $out1 = system(&quot;df -k&quot;); print &quot;The output of df -k command is : $out1 &quot;; Method1: Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda8 19346964 10931664 7432528 60% / /dev/hda1 101089 14826 81044 16% /boot /dev/hda3 15116868 12328832 2020132 86% /home none 252056 0 252056 0% /dev/shm /dev/hda5 8064272 5384612 2270008 71% /usr /dev/hda6 3020140 307088 2559636 11% /var /dev/hda2 30233928 8830792 19867324 31% /usr/local The output of df -k command is : 0
    5. 5. Simple example – way to execute external command print &quot;Method2: &quot;; my $out2 = `df -k`; print &quot;The output of df -k command is : $out2 &quot;; Method2: The output of df -k command is : Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda8 19346964 10931664 7432528 60% / /dev/hda1 101089 14826 81044 16% /boot /dev/hda3 15116868 12328832 2020132 86% /home none 252056 0 252056 0% /dev/shm /dev/hda5 8064272 5384612 2270008 71% /usr /dev/hda6 3020140 307088 2559636 11% /var /dev/hda2 30233928 8830792 19867324 31% /usr/local [sopan@ps3724 tutorial]$
    6. 6. An introduction to Simple Stuff <ul><li>Perl Variables – How perl treats integers, floating numbers or strings? Give simple examples. </li></ul><ul><li>Play with variables – assign, modify, print the values. </li></ul><ul><li>Explain about “my” syntax. </li></ul><ul><li>Arithmetic Operations (+, -, * etc) on int/float and strings. </li></ul><ul><li>Introduction to loops (if-else, while, for) </li></ul><ul><li>Comparison operators – (>, <, ==, eq, nq etc) </li></ul><ul><li>Introduction to special variable $_ </li></ul><ul><li>How to use command line argument in the script –though arrays will be introduced later. </li></ul>
    7. 7. Exercise <ul><li>Find the maximum from the given set of integers. </li></ul><ul><li>Take two numbers from user – print the addition of these numbers </li></ul><ul><li>Greatest Common Divisor – Implement following algorithm </li></ul>gcd (a, b) { if (b < a ) { swap (a, b); } While (b) { r = b % a; a = b; b = r; } return a; }
    8. 8. Directory and File Operations <ul><li>File Operations – Read the file, Write the file, Append the file. </li></ul><ul><li>Introduction to $! </li></ul><ul><li>Introduction to die </li></ul><ul><li>Introduction to chomp </li></ul><ul><li>Unlink </li></ul>Exercise– Write the program to monitor given set of hosts in the network.
    9. 9. Arrays and Functions <ul><li>Arrays, split, join functions, pop, push, shift, unshift functions. </li></ul><ul><li>Exercises </li></ul><ul><li>Example 1. Counting number of lines from a given file. </li></ul><ul><li>Example 2. Counting number of words from a file (… what is word?) </li></ul><ul><li>Example 3. Various operations on /etc/password – e.g. Which userid do not have user-gecos? </li></ul>
    10. 10. Exercise – long assignement <ul><li>Example-Data </li></ul><ul><li>We would like to provide the following services: </li></ul><ul><li>Q1. Given Year, won/lost category, print team name. </li></ul><ul><li>Q2. Given Year, Print all entries for that year. </li></ul><ul><li>Q3. For Won/Lost – print year and teams. </li></ul><ul><li>Q4. Print all entries sorted by Won/Lost  or By Year. </li></ul>1975:Won:West Indies 1975:Lost:Australia 1979:Won:West Indies 1979:Lost:England 1983:Won:India 1983:Lost:West Indies 1987:Won:Australia 1987:Lost:England 1992:Won:Pakistan 1992:Lost:England 1996:Won:Srilanka 1996:Lost:Australia
    11. 11. grep and map functions <ul><li>List Filtering with grep </li></ul>my @result = grep EXPR @input_list; my $count = grep EXPR @input_list; my @input_numbers = (1, 4, 50, 6 14); my @result = grep $_>10, @input_numbers; Transforming Lists with Map my @input_list = (1, 4, 10, 56, 100); my @result = map $_ + 100, @input_list; my @next_result = map ($_, 5*$_), @input_list; my %hash_result =map ($_, $_*$_), @input_list;
    12. 12. Exercise <ul><li>Q. 1 Write a program that takes a list of filenames on the command line and </li></ul><ul><li>uses grep to select the ones whose size in bytes is less than 1000. Use map to </li></ul><ul><li>transform the strings in this list, putting four space characters in front of </li></ul><ul><li>each and a newline character after. Print the resulting list. </li></ul>
    13. 13. Regular Expression <ul><li>Q. What is a regular expression? </li></ul><ul><li>Ans. A regular expression is simply a string that describes a pattern. </li></ul><ul><li>Q. So what is pattern? </li></ul><ul><li>Ans. Let us understand by example: </li></ul><ul><li>ls *.txt, </li></ul><ul><li>dir *.* </li></ul><ul><li>are examples of patterns. </li></ul><ul><li>author:sopan_shewale can be example of search pattern in for Search on content management site or for search engine. </li></ul><ul><li>In Perl, the patterns described by regular expressions are used to search </li></ul><ul><li>strings, extract desired parts of strings, and to do search and replace </li></ul><ul><li>operations. </li></ul><ul><li>Regular Expression is often abbrevated as regexp, regex. </li></ul>
    14. 14. Regular expression (Cont…) Let us look at the example if (&quot;Hello World &quot; =~ /World/) { print &quot;It matches &quot;; } else { print &quot;It doesn't match &quot;; } The sense of =~ is reversed by !~ operator.
    15. 15. Regular Expression (Cont…) The literal string in the regexp can be replaced by a variable: $greeting = &quot;World&quot;; if (&quot;Hello World&quot; =~ /$greeting/) { print &quot;It matches &quot;; } else { print &quot;It doesn't match &quot;; } Regexp’s are case sensitive
    16. 16. Regular Expression (Cont…) <ul><li>If a regexp matches in more than one place in the string, perl will always </li></ul><ul><li>match at the earliest possible point in the string: </li></ul>&quot;Hello World&quot; =~ /o/; # matches 'o' in 'Hello' &quot;That hat is red&quot; =~ /hat/; # matches 'hat' in 'That' &quot;2+2=4&quot; =~ /2+2/; # doesn't match, + is a metacharacter &quot;2+2=4&quot; =~ /2+2/; # matches, + is treated like an ordinary + Some characters, called metacharacters , are reserved for use in regexp notation. List is : {}[]()^$.|*+?
    17. 17. <ul><li>Where in the string the regexp should try to match – Use ^ and $ . </li></ul><ul><ul><li>The anchor ^ : match at the beginning of the string </li></ul></ul><ul><ul><li>The anchor $ : match at the end of the string, </li></ul></ul>Regular Expression (Cont…) %vi simple_grep #!/usr/bin/perl $regexp = shift ; while (<>) { print if /$regexp/; } &quot;housekeeper&quot; =~ /keeper/; # matches &quot;housekeeper&quot; =~ /^keeper/; # doesn't match &quot;housekeeper&quot; =~ /keeper$/; # matches &quot;housekeeper &quot; =~ /keeper$/; # matches &quot;keeper&quot; =~ /^keep$/; # doesn't match &quot;keeper&quot; =~ /^keeper$/; # matches &quot;&quot; =~ /^$/; # ^$ matches an empty string Grep Kind of example
    18. 18. Using character classes <ul><li>A character class allows a set of possible characters, rather than just </li></ul><ul><li>a single character, to match at a particular point in a regexp. </li></ul>$x = 'bcr'; /[x]at/; # matches 'at', 'bat, 'cat', or 'rat' /item[0-9]/; # matches 'item0' or ... or 'item9' /[0-9bx-z]aa/; # matches '0aa', ..., '9aa', /cat/; # matches 'cat' /[bcr]at/; # matches 'bat, 'cat', or 'rat' /item[0123456789]/; # matches 'item0' or ... or 'item9‘ &quot;abc&quot; =~ /[cab]/; # matches 'a' In the last statement, even though 'c' is the first character in the class, 'a‘ matches because the first character position in the string is the earliest point at which the regexp can match. Regular Expression (Cont…)
    19. 19. <ul><li>d is a digit and represents [0-9] </li></ul><ul><li>s is a whitespace character and represents [ f] </li></ul><ul><li>w is a word character (alphanumeric or _) and represents [0-9a-zA-Z_] </li></ul><ul><li>D is a negated d; it represents any character but a digit [^0-9] </li></ul><ul><li>S is a negated s; it represents any non-whitespace character [^s] </li></ul><ul><li>W is a negated w; it represents any non-word character [^w] </li></ul><ul><li>The period '.' matches any character but &quot; &quot; </li></ul>Regular Expression (Cont…)
    20. 20. Matching this or that <ul><li>This is accomplished by using the alternation metacharacter | </li></ul>&quot;cats and dogs&quot; =~ /cat|dog|bird/; # matches &quot;cat&quot; &quot;cats and dogs&quot; =~ /dog|cat|bird/; # matches &quot;cat&quot; Regular Expression (Cont…)
    21. 21. Grouping things and hierarchical matching <ul><li>sometime we want alternatives for just part of a regexp The </li></ul><ul><li>grouping metacharacters () solve this problem </li></ul>/(a|b)b/; # matches 'ab' or 'bb‘ /(ac|b)b/; # matches 'acb' or 'bb' /(^a|b)c/; # matches 'ac' at start of string or 'bc' anywhere /(a|[bc])d/; # matches 'ad', 'bd', or 'cd' /house(cat|)/; # matches either 'housecat' or 'house‘ /house(cat(s|)|)/; # matches either 'housecats' or 'housecat' or # 'house'. Note groups can be nested. /(19|20|)dd/; # match years 19xx, 20xx, or the Y2K problem, xx &quot;20&quot; =~ /(19|20|)dd/; # matches the null alternative '()dd', # because '20dd' can't match Regular Expression (Cont…)
    22. 22. <ul><li>The process of trying one alternative, seeing if it matches, </li></ul><ul><li>and moving on to the next alternative if it doesn't, is called </li></ul><ul><li>backtracking . </li></ul><ul><li>To be concrete, here is a step-by-step analysis of what perl </li></ul><ul><li>does when it tries to match the regexp </li></ul>&quot;abcde&quot; =~ /(abd|abc)(df|d|de)/; Regular Expression (Cont…)
    23. 23. [1]. Start with the first letter in the string 'a'. [2]. Try the first alternative in the first group 'abd'. [3]. Match 'a' followed by 'b'. So far so good. [4]. 'd' in the regexp doesn't match 'c' in the string – a dead end. So backtrack two characters and pick the second alternative in the first group 'abc'. [5]. Match 'a' followed by 'b' followed by 'c'. We are on a roll and have satisfied the first group. Set $1 to 'abc'. [6]. Move on to the second group and pick the first alternative 'df'. [7]. Match the 'd'. [8]. 'f' in the regexp doesn't match 'e' in the string, so a dead end. Backtrack one character and pick the second alternative in the second group 'd'. [9]. 'd' matches. The second grouping is satisfied, so set $2 to 'd'. [10]. We are at the end of the regexp, so we are done! We have matched 'abcd' out of the string &quot;abcde&quot;. Regular Expression (Cont…)
    24. 24. Extracting Matches <ul><li>The grouping metacharacters () allow the extraction of the parts of the </li></ul><ul><li>string that matched. </li></ul><ul><li>The extracted stuff is put into the special variables $1, $2, etc </li></ul># extract hours, minutes, seconds if ($time =~ /(dd):(dd):(dd)/) { # match hh:mm:ss format $hours = $1; $minutes = $2; $seconds = $3; } Regular Expression (Cont…)
    25. 25. Matching Repetitions <ul><li>metacharacters ?, * , + , and {} play a vital role in </li></ul><ul><li>matchings. </li></ul><ul><li>a? = match 'a' 1 or 0 times </li></ul><ul><li>a* = match 'a' 0 or more times, i.e., any number of times </li></ul><ul><li>a+ = match 'a' 1 or more times, i.e., at least once </li></ul><ul><li>a{n,m} = match at least n times, but not more than m times. </li></ul><ul><li>a{n,} = match at least n or more times </li></ul><ul><li>a{n} = match exactly n times </li></ul>Regular Expression (Cont…)
    26. 26. A few Principles <ul><li>Principle 0: Taken as a whole, any regexp will be matched at the </li></ul><ul><li>earliest possible position in the string. </li></ul><ul><li>Principle 1: In an alternation a|b|c... , the leftmost alternative that </li></ul><ul><li>allows a match for the whole regexp will be the one used. </li></ul><ul><li>Principle 2: The maximal matching quantifiers ?, * , + and {n,m} will </li></ul><ul><li>in general match as much of the string as possible while still allowing </li></ul><ul><li>the whole regexp to match. </li></ul>Regular Expression (Cont…)
    27. 27. <ul><li>Principle 3: If there are two or more elements in a regexp, the leftmost </li></ul><ul><li>greedy quantifier, if any, will match as much of the string as possible while </li></ul><ul><li>still allowing the whole regexp to match. The next leftmost greedy </li></ul><ul><li>quantifier, if any, will try to match as much of the string remaining </li></ul><ul><li>available to it as possible, while still allowing the whole regexp to match. </li></ul><ul><li>And so on, until all the regexp elements are satisfied. </li></ul>A few Principles Regular Expression (Cont…)
    28. 28. <ul><li>Principle 0 overrides the others - the regexp will be matched as </li></ul><ul><li>early as possible, with the other principles determining how </li></ul><ul><li>the regexp matches at that earliest character position. </li></ul>$x = &quot;The programming republic of Perl&quot;; $x =~ /^(.+)(e|r)(.*)$/; # matches, # $1 = 'The programming republic of Pe' # $2 = 'r' # $3 = 'l' Regular Expression (Cont…)
    29. 29. Exercise <ul><li>Problem 1: Let us match both integers and floating point numbers from text, ignore other parts. </li></ul><ul><li>Problem 2. Match Email Addresses or collect all email addresses from given text topic. </li></ul><ul><li>Problem 3. $string = “/some/path/in/directory/html”; print only last part – last level directory name. </li></ul>
    30. 30. Regular Expression – Match the positive Integer <ul><li>You might start with expression like /[0-9]+/ which is for &quot;one or more digits&quot;. </li></ul><ul><li>Then you might do simplification – to /d+/ - but still it is wrong, why? Expression like &quot;abc123de“ fails - Opps </li></ul><ul><li>So you are moving to add anchors like /^d+$/ . </li></ul><ul><li>This this is not correct – the new line char troubles us- the expression can match &quot;123 &quot; as well as &quot;123“ - oops! </li></ul><ul><li>Now the modern Perl versions provide the z anchor, - The best answer to our problem could be /^d+z/ . </li></ul><ul><li>But still issues - Although deprecated, the $* variable controls the matching of ^ and $ to permit internal newline matches as well as end-of-string matches. </li></ul><ul><li>The string &quot;foobar 123&quot; will also match our new regular expression - Oops again. </li></ul><ul><li>Let us go to the final answer – The best answer is /Ad+z/ , which says, &quot;beginning of string&quot; followed by &quot;one or more digits&quot; followed by &quot;end of string&quot;. </li></ul><ul><li>The answer is: /Ad+z/ - finally  </li></ul>Question: Determine whether a string contains a positive integer. Discussion:
    31. 31. Hashes <ul><li>Defination: Hashes are like arrays but scalar indexes. </li></ul><ul><li>Example Defination: </li></ul>my %fruit; $fruit{&quot;red&quot;} = &quot;apple&quot;; $fruit{&quot;orange} = &quot;orange&quot;; $fruit{&quot;purple&quot;} = &quot;grape&quot;; %fruit = (&quot;red&quot;, &quot;apple&quot;, &quot;orange&quot;, &quot;orange&quot;, &quot;purple&quot;, &quot;grape&quot;); %fruit = (         &quot;red&quot; => &quot;apple&quot;,         &quot;orange&quot; => &quot;orange&quot;,         &quot;purple&quot; => &quot;grape&quot;, );
    32. 32. <ul><li>Functions on Hashes: </li></ul><ul><li>delete </li></ul><ul><li>Keys </li></ul><ul><li>values each </li></ul>Functions on Hashes #vi my %fruit = (         &quot;red&quot; => &quot;apple&quot;,         &quot;orange&quot; => &quot;orange&quot;,         &quot;purple&quot; => &quot;grape&quot;, ); for (keys %fruit) { print “$_ : $fruit{$_} ”; } Why use Hash? Write a program which takes the input the city/capital name and returns the country name by Using Arrays and Hashes or any other method. So you know why use Hashes.
    33. 33. References # Create some variables $a = &quot;mama mia&quot;; @array = (10, 20); %hash = (&quot;laurel&quot; => &quot;hardy&quot;, &quot;nick&quot; => &quot;nora&quot;); # Now create references to them $ra = $a; # $ra now &quot;refers&quot; to (points to) $a $rarray = @array; $rhash = hash; #You can create references to constant scalars in a similar fashion: $ra = 10; $rs = &quot;hello world&quot;;
    34. 34. References <ul><li>Dereferencing: Means getting at the value that a reference point to. </li></ul>#Look nicely: @array = (10, 20); $ra = @array; is similar to $ra =[10, 20] # Notice the square braces. %hash = (&quot;laurel&quot; => &quot;hardy&quot;, &quot;nick&quot; => &quot;nora&quot;); $rhash = hash is similar to $rhash = { “laurel”=>”hardy”, “nick” => “nora” }; $ra = $a; # First take a reference to $a $$ra += 2; # instead of $a += 2; print $$ra; # instead of print $a $rarray = @array; push (@array , &quot;a&quot;, 1, 2); # Using the array as a whole push (@$rarray, &quot;a&quot;, 1, 2); # Indirectly using the ref. to the array $rhash = hash; print $hash{&quot;key1&quot;}; # Ordinary hash lookup print $$rhash{&quot;key1&quot;}; # hash replaced by $rhash
    35. 35. <ul><li>Shortcuts with the Arrow Notation </li></ul>$rarray = @array; print $rarray->[1] ; # The &quot;visually clean&quot; way $rhash = hash; print $rhash->{&quot;k1&quot;}; #instead of ........ print $$rhash{&quot;k1&quot;}; # or print ${$rhash}{&quot;k1&quot;}; References
    36. 36. Subroutines <ul><li>Q. Why Subroutines exists in Programming? </li></ul><ul><li>Ans. Do I need to Answer? </li></ul><ul><li>Defining subroutine: </li></ul>#Defining subroutine: sub mysubroutinename { #### code to do that } <ul><li>How to execute subroutine? </li></ul><ul><li>How to pass the arguments to subroutines? </li></ul><ul><li>How to use those arguments passed to the subroutines? </li></ul><ul><li>Return Values? </li></ul>
    37. 37. Modules <ul><li>Perl Allows you to partition your code into one more reusable module. </li></ul><ul><li>Modules is code reuse </li></ul><ul><li>We will see: </li></ul><ul><li>Define Modules using the package keyword </li></ul><ul><li>Load pre-defined modules using “use” and “require” keywords. </li></ul><ul><li>Access package specific variables and subroutines using “::” notation. </li></ul><ul><li>Load Functions at Run Time. </li></ul>
    38. 39. <ul><li>Remember that modules are not intended to be standalone applications </li></ul><ul><li>we'll never actually be running our module by itself . Instead, we'll be </li></ul><ul><li>using our module to provide added functionality to a larger script </li></ul><ul><li>Let us look at the example: Filename is </li></ul>Modules (Cont…) Package SayHello; sub hello_package { return “Hello, Welcome to the world of Modules”; } 1;
    39. 40. <ul><li>Use of “use” keyword </li></ul><ul><ul><li>This is simplest way to pull the module into your script </li></ul></ul><ul><ul><li>Searches all the paths in the array @INC until it finds a file </li></ul></ul><ul><li>Use “require” command: </li></ul><ul><li>What’s the difference then? </li></ul><ul><li>When you load a module using use, the module is loaded and executed </li></ul><ul><li>at compile time , even before the remaining portion of the script is </li></ul><ul><li>compiled. </li></ul><ul><li>require pulls in the code of the module at run-time; and if the file </li></ul><ul><li>cannot be found generates a run time error </li></ul><ul><li>Note on variables declared with “my” you will not be able to access it from outside the module </li></ul><ul><li>If you must access a module variable from outside the package you are declaring it in, then you can declare it using the our function </li></ul>use and require – what is that?
    40. 42. <ul><li>For the decent example – may be if you are thinking of contributing to Have a look at </li></ul><ul><li>bless : This operator takes the reference and converts it into object. </li></ul><ul><li>Some Useful work module – </li></ul>
    41. 44. CGI <ul><li>Check my other PPT </li></ul><ul><li>Explore the application available at </li></ul><ul><ul><li>MD5 Algorithm for Encryption </li></ul></ul><ul><ul><li>The module is used by Yahoo etc </li></ul></ul>
    42. 45. Example: Count Click Script #!/usr/bin/perl ######################### ## Author: Sopan Shewale ## Company: Persistent Systems Pvt Ltd ## This script is created for giving demo on click count. ## The Script is support to display increse/decrease ##click's, handles back button of browser, does not ##handle reload stuff. ## also it's based on sessions. ######################## use strict; use warnings; use CGI; use CGI::Session; use CGI::Cookie; my $q = new CGI(); my $sessionid = $q->cookie(&quot;CGISESSID&quot;) || undef; my $session = new CGI::Session(undef, $sessionid, {Directory=>'/tmp'}); $sessionid = $session->id(); my $cookie = new CGI::Cookie(-name=>'CGISESSID', -value=>$sessionid, -path=>&quot;/&quot;); print $q->header('text/html', -cookie=>$cookie); print $q->start_html(&quot;Welcome to Click Count Demo&quot;); print &quot;<h1>Welcome to Click Count Demo</h1>&quot;; my $count = $session->param('count'); ## count-is click count variable if(!defined($count)) { $session->param('count', 0); $count=0;} ### if session is first time created, set count=0 $session->param('count', $count); $count = $session->param('count'); #print &quot;<h1>The Click Count is: $count &quot;; ## Form stuff print $q->startform(-method=>'POST'); print $q->submit( -name=>&quot;Increase&quot;, -value=>'Increase1'); print $q->submit( -name=>&quot;Decrease&quot;, -value=>'Decrease1'); print $q->endform();
    43. 46. Example: Count Click Script (Cont…) ## Which button is being pressed my $which_button = $q->param('Increase'); if(defined ($which_button)) { print &quot;Increase pressed&quot;; $count = increase_count($count); ## Increase the count since increase button is clicked $session->param('count', $count); }else { $which_button=$q->param('Decrease'); if(defined($which_button)){ print &quot;Decrease pressed&quot;; $count = decrease_count($count); ## Decrease the count since decrease button is clicked $session->param('count', $count); } else {print &quot;You have not pressed any button, seems you are typing/re-typing the same URL&quot;; } } $count = $session->param('count'); print &quot;<h1>The Click Count is: $count &quot;; print $q->end_html(); ## increases the count by 1 sub increase_count { my $number = shift; $number = $number +1; return $number; } ## decreases the count by 1 sub decrease_count { my $number = shift; $number = $number -1; return $number; }
    44. 47. Using eval <ul><li>String Form: Expression Evaluation </li></ul><ul><li>The Block Form: Exception Handling </li></ul><ul><li>Possible to use eval for time-outs. </li></ul><ul><li>A few more… </li></ul>
    45. 48. Data::Dumper
    46. 49. TWiki
    47. 50. bin: view, edit, search etc tools: mailnotify template: Templates (view.tmpl), also has skin related data lib: modules and required libraries, plugin code data: webs directories (e.g. Main,TWiki) and each directory inside contains the topics from that web. The topics are companied by there version history pub: Attachments of the topics and commonly shared data
    48. 51. <ul><li>Basic request in TWiki from browser side, calls some script from bin </li></ul><ul><li>Directory (like views) which Loads setlib.cfg from the same </li></ul><ul><li>directory. Which loads LocalSite.cfg from lib directory. The </li></ul><ul><li>LocalSite.cfg has site related Configuration variables defined. </li></ul><ul><li>Then the relevant modules are loaded, topic are read, macros expanded, the </li></ul><ul><li>content converted into html page and sent back to browser, request is </li></ul><ul><li>completed. </li></ul><ul><li>Now a days the LocalSite.cfg is written using Web-Interface, For example </li></ul><ul><li> </li></ul>TWiki (Cont…)
    49. 52. TWiki (Cont…) <ul><li>What is plugins?: </li></ul><ul><li>One can add plugins to TWiki to extend the functionality of TWiki </li></ul><ul><li>without altering the core code. Plugin approach lets us do following: </li></ul><ul><li>add virtually unlimited features while keeping the main TWiki code compact and efficient; </li></ul><ul><li>heavily customize an installation and still do clean updates to new versions of TWiki; </li></ul><ul><li>rapidly develop new TWiki functions in Perl using the Plugin API. </li></ul>
    50. 53. <ul><li>TWiki Community: The plugins are located at </li></ul><ul><ul><li> </li></ul></ul><ul><li>Each plugin has couple of topics on the site for support, development, </li></ul><ul><li>installation instruction. </li></ul><ul><li>Let us look at example: </li></ul><ul><li> : Has comment Plugin, with installation instructions, syntax etc. </li></ul><ul><li> : Used for support activity and comments from public. </li></ul><ul><li> : Appraisal purpose, any one can appraise the plugin. </li></ul><ul><li>The plugin developer must read: </li></ul><ul><li>TWiki::Func ( ) code. </li></ul><ul><li>That’s the Plugin API. </li></ul>TWiki (Cont…)
    51. 54. <ul><li>General Instructions for creating Plugin </li></ul><ul><li>The plugin name is in the format <name>Plugin. </li></ul><ul><li>The code goes in <TWikiRootDirectory>/lib/TWiki/Plugings/ directory. </li></ul><ul><li>TWiki provides plugin called EmptyPlugin which can be used as Template to develop new plugin. </li></ul><ul><li>The code of Empty Plugin is <TWikiRootDirectory>/lib/TWiki/Plugins/ </li></ul><ul><li>Create a <name>Plugin topic in the TWiki web. The topic contains the settings, installation instructions and syntax of the plugin. </li></ul><ul><li>Enable Plugin by using configure e.g. </li></ul>TWiki (Cont…)
    52. 55. <ul><li>HelloPlugin </li></ul>%HELLO{format=“Dear $first $last, $brWelcome to the world of TWiki” first=“Hari” last=“Sadu”}% Dear Hari Sadu, Welcome to the world of TWiki This should get expanded to:
    53. 58. Database Connectivity <ul><li>DBI Module </li></ul><ul><li>General process used in database activity </li></ul><ul><ul><li>Connect </li></ul></ul><ul><ul><li>Prepare sql query </li></ul></ul><ul><ul><li>Execute </li></ul></ul><ul><ul><li>Finish </li></ul></ul><ul><ul><li>Disconnect </li></ul></ul><ul><li>Best document available at </li></ul>
    54. 59. Exercise <ul><li>Q. 1: Given array, delete the duplicate entries – the order </li></ul><ul><li>should be reserved e.g. For input Array - (“Proxy”, </li></ul><ul><li>“ Proxy”, “smtp”, “smtp”, “smtp”, “mail”, 25) - output </li></ul><ul><li>should be (“proxy”, “smtp”, “mail” 25); </li></ul>
    55. 60. References <ul><li>Online </li></ul><ul><ul><li> - Simon Cozens </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li>http:// </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>Books </li></ul><ul><ul><li>Advanced Perl Programming – By Sriram Srininivasan </li></ul></ul><ul><ul><li>Learning Perl Objects, References, & Modules – Randal L. Schwartz </li></ul></ul><ul><ul><li>Intermediate Perl – Randal L. Schwartz </li></ul></ul><ul><ul><li>Perl for Systems Administration – David N. Blank </li></ul></ul><ul><ul><li>Mastering Algorithms with Perl – Jon Orwant et all </li></ul></ul><ul><li>People to Track </li></ul><ul><ul><li>Randal L. Schwartz </li></ul></ul><ul><ul><li>Simon Cozens </li></ul></ul><ul><ul><li>Convey - ??? </li></ul></ul>
    56. 61. References (Cont…) <ul><li>Tools </li></ul><ul><ul><li>Web Application Development - Frameworks </li></ul></ul><ul><ul><ul><li>CGI::Application ( http:// / ) </li></ul></ul></ul><ul><ul><ul><li>Catalyst ( http:// / ) </li></ul></ul></ul><ul><ul><ul><li>PageKit Web Application Framework ( http:// / ) </li></ul></ul></ul><ul><ul><ul><li>Combust web site Framework ( http:// / ) </li></ul></ul></ul><ul><ul><ul><li>Mason ( ) </li></ul></ul></ul><ul><ul><ul><li>Embperl ( http:// / ) </li></ul></ul></ul><ul><ul><li>Template Tools – used in Web Application Development </li></ul></ul><ul><ul><ul><li>Template Toolkit </li></ul></ul></ul><ul><ul><ul><li>HTML::Template http://html- / </li></ul></ul></ul><ul><ul><ul><li>Petal - </li></ul></ul></ul><ul><ul><li>Other </li></ul></ul><ul><ul><ul><li>TWiki ( ) – Enterprise Collaboration Platform </li></ul></ul></ul><ul><ul><ul><li>Sympa - Mailing List </li></ul></ul></ul><ul><ul><ul><li>Mhon-Arch – Mail Archiving Soltion </li></ul></ul></ul><ul><ul><ul><li>Webmin – Unix System Administration Application </li></ul></ul></ul>
    57. 62. <ul><li>Thank You </li></ul>