1 / 35

Week Four Agenda

Week Four Agenda. Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines Lab assistance, questions and answers. Announcements. Script Comments Scripts should contain the following comments:

adeola
Download Presentation

Week Four Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week Four Agenda • Announcements • Link of the week • Review week three lab assignment • This week’s expected outcomes • Next lab assignment • Break-out problems • Upcoming deadlines • Lab assistance, questions and answers

  2. Announcements Script Comments Scripts should contain the following comments: Editing Author: Script Functionality: Lab Assignment: Due Date:

  3. Link of the Week Object Code • http://freedom-to-tinker.com/blog/felten/source-code-and-object-code • What is object code? • Object File Format • What is Executable and Linking Format?

  4. Link of the Week

  5. Link of the Week

  6. Review Week Three Lab Assignment What is a filter? A filter is a UNIX command that does some manipulation of the text of a file. It utilizes both stdin and stdout. UNIX Command Line awk, cat, cut, expand, compress, fold, grep, head, nl, perl, pr, sed, sh, sort, split, strings, tail, tac, tee, tr, uniq, and wc

  7. Review Week Three Lab Assignment File System cat, cd,chmod,chown,chgrp, cksum, cmp, cp, dd, du, df, fsck, fuser, ln, ls, lsattr, lsof, mkdir, mount, mv, pwd, rm, rmdir, split, touch, umask Processes at, chroot, cron, exit, kill, killall, nice, pgrep, pidof, pkill, ps, pstree, sleep, time, top, and wait

  8. Review Week Three Lab Assignment Test Command A common way to set up a condition for the if command is with the test command. test condition or [ condition ] The test command evaluates the condition and returns 0 or 1, depending on the results of the test. The brackets work exactly like the test condition. The open bracket is a link to test.

  9. Review Week Three Lab Assignment Constructing Conditions -s file -r file -w file -x file -f file -d file Examples: if [ ! –f /etc/.fsckask ] If the plain file /etc/.fsckask does not exist If [ -d /etc/rc0.d ] If there is a directory named /etc/rc0.d

  10. Review Week Three Lab Assignment Perl is a simple language that compiles and executes like a shell or batch type file. Perl doesn’t impose special growth limitations on an array or data strings Perl is a composite of C, AWK, and Basic. Perl was originally developed to manipulate text information.

  11. Review Week Three Lab Assignment • Perl’s capabilities range from - System administration - Web development - Network programming - GUI development • Perl’s major features are • Procedural Programming makes use of simple sequential steps, routines, subroutines, and methods. • Object Oriented Programming (OOP) makes use of “objects”. The key elements of are inheritance, modularity, polymorphism, and encapsulation.

  12. Review Week Three Lab Assignment Perl and Shell Similarities Perl scalar@ARGV ~ Shell $# Perl $ARGV[0] ~ Shell $1 Perl $ARGV[1] ~ Shell $2 Perl unless(scalar(@ARGV)==2) ~ Shell if [ $# != 2] All Perl statements are terminated with a “;” Perl exit 0 is returned if execution was successful. Perl exit 1 is returned if execution fails.

  13. Review Week Three Lab Assignment Perl syntax $? - this variable contains the return value # - precedes a comment statement in Perl \n - new line syntax “ …” $strexp = “This text is considered as a string”; ‘ …’ $charexp = ‘a’; ` …` $cmdexp = `ls –l`; @ARGV – array containing command line arguments $_ - default implied scalar

  14. Review Week Three Lab Assignment There are two types of relational operators. One class operates on numeric values, the other on string values. Relational operators NumericStringMeaning > gt Greater than >= ge Greater than or equal < lt Less than <= le Less than or equal

  15. Review Week Three Lab Assignment Equality Operators NumericStringMeaning == eq Equal to != ne Not equal to  cmp Comparison, sign results -1 if the left operand is less 0 If both operands equal 1 If the left operand is greater

  16. Review Week Three Lab Assignment Commands cal –y (display a calandar for the year) cal –j 2009 (display Julian dates) cal –m 2009 (display Monday first day) cal –s 2009 (display Sunday first day) cal 9 2009 (display September 2009 month)

  17. Week Four Expected Outcomes Learning Outcomes • Write Perl scripts, including variables, control flow, and regular expression syntax

  18. Next Lab Assignment • Perl is designed to - Process text data - Perform pattern matching - Utilize string handling tasks • Perl is available on many platforms - UNIX - Linux - HP-UX

  19. Next Lab Assignment Perl utilizes two types of categories - Singular variables that represent a single-value. The variable prefix symbol for a scalar is the $. - Plural variables are ones that contain multiple-values. Arrays and hashes are two multi-valued variables.

  20. Next Lab Assignment Perl data types $answer = 42; (an integer) $pi = 3.14159265; (a “real” number) $animal = “horse”; (string) $statement = “I exercise my $animal”; (string with interpolation) $amount = ‘It cost me $5.00’; (string without interpolation) $cwd = `pwd`; (string output from a command)

  21. Next Lab Assignment @garage = (“car”, “mower”, “broom”); Definition: An array is an ordered list of scalars, accessed by the scalar’s position in the list. @persons = (“Will”, “Karim”, “Asma”, “Jay”); $count = @persons; Demonstrate: Execute week_four.pl script

  22. Next Lab Assignment Open Statement The open function can be used to create file handles for different purposes (input, output, piping), you need to be able to specify which behavior you want.

  23. Next Lab Assignment open functions open(file_handler, “file_name”) open(file_handler, “<file_name”) open (file_handler, “>file_name”) open (file_handler, “>>file_name”)

  24. Next Lab Assignment Filehandle is utilized for both input and output files. Most file names are cryptic and are meaningless to programmers. The purpose of a filehandle is to help the programmer remember a simple file name throughout a program. A filehandle is a name given for a file, device, socket, or pipe. Filehandle command line format: open(filehandle, file name, permissions, chmod); Example: open($FH,$file_name);

  25. Next Lab Assignment What is List Processing? @math_array = (6 - 4, 4 * 4, 8 / 2, 9 - 8); while ( … ) { … }

  26. Next Lab Assignment What is a for loop? for (counter = 0; counter < 10; counter++) { … } Three expressions are contained in a for loop: • Set initial state of the loop variable • Condition test the loop variable • Modify the state of the loop variable

  27. Next Lab Assignment foreach VAR (List) { … } Demonstrate: Execute read_list.pl script @myNames = ('Larry', 'Curly', 'Moe');foreach (@myNames) { print $_;} Demonstrate: Execute sum_list.pl script

  28. Next Lab Assignment #!/usr/bin/perl -w # Author: Bob D'Andrea # Script name: arry_sort.pl # Command line: ./arry_sort.pl @dudes = ( "Bob", "Jake", "Sam", "Ken", "Rockie", "Homer" ); @dudes = sort(@dudes); @chicks = ( "Jamie", "Gloria", "Sue", "Brittany" ); @chicks = sort(@chicks); print " @dudes","\n"; print " @chicks","\n"; Demonstrate : arry_sort.pl

  29. Next lab assignment Perl Program Statement #!/usr/bin/perl #!/usr/bin/perl -w Print continuation statement print "error: incorrect number of arguments", "\n", "usage: intlist a b (where a < b)", "\n"; Demonstrate: Execute linenum.pl and intlist.pl scripts.

  30. Break-out problems • $strexp = “This text is considered as a string”; • $intexp = 10; • $floatptexp = 2.54; • $charexp = ‘a’; • $cmdexp = `ls –l`; • $argexp = (“two”, “four”, “six”); • @array_exp = (“Jackie”, “Vicki”, “Alex”); • $array [0] = “new value”; • $a = $b + 5; • $container = @container; • ($map{blue}, $map{orange}, $map{jade}) = (0xff0000, 0x00ff00, 0x0000ff0);

  31. Next Lab Assignment Programming Perl text book reading Chapter One Chapter Two Chapter Three

  32. Upcoming deadlines Lab Assignment 3-1 is due on October 3, 2010. Lab Assignment 4-1 is due on October 10, 2010. Lab Assignment 7-1, Midterm exam administered from October 18 through 22. Midterm outline will be posted on the Bulletin Board by October 10, 2010.

  33. Questions and answers • Questions • Comments • Concerns • After class, I will help students with their scripts.

More Related