Exercise Solutions. Chapter 1. Chapter 2 APPENDIX. #!/usr/bin/perl -w # chap01ex1. pl. print "Hi Mom.\nThis is my second program.

Size: px
Start display at page:

Download "Exercise Solutions. Chapter 1. Chapter 2 APPENDIX. #!/usr/bin/perl -w # chap01ex1. pl. print "Hi Mom.\nThis is my second program."

Transcription

1 APPENDIX Exercise Solutions This appendix contains the answers to the chapter exercises. An important note: each solution is an answer, not the answer. Remember that in Perl, there is more than one way to do it, and that applies to these solutions as well. Chapter 1 1. # chap01ex1. pl print "Hi Mom.\nThis is my second program.\n"; Chapter 2 1. # chapo2ex1.pl print "Currency converter\n\n"; print "Please enter the exchange rate: "; chomp(my $yen= <STDIN>); print "Enter first price to convert: "; chomp(my $price1 = <STDIN>); print "Enter second price to convert: "; chomp(my $price2 = <STDIN>); 385

2 386 APPENDIX EXERCISE SOLUTIONS print "Enter third price to convert: "; chomp(my $price3 = <STDIN>); print "$price1 Yen is ", ($price11$yen), " dollars\n"; print "$price2 Yen is ", ($price21$yen), " dollars\n"; print "$price3 Yen is ", ($price31$yen), " dollars\n"; 2. #!lusrlbinlperl -w # chap02ex2.pl print "enter a hex number: "; chomp(my $hexnum = <STDIN>); print "converted to an int: ", hex($hexnum), "\n"; print "enter an octal number: "; chomp(my $octal = <STDIN>); print "converted to an int: ", oct($octal), "\n"; 3. #!lusrlbinlperl -w # chap02ex3.pl print "enter a value less than 256: "; chomp(my $bin = <STDIN>); print((128 & $bin) I 128); print((64 & $bin) I 64); print((32 & $bin) I 32); print((16 & $bin) I 16); print((8 & $bin) I 8); print((4 & $bin) I 4); print((2 & $bin) I 2); print((1 & $bin) I 1); print "\n";

3 APPENDIX EXERCISE SOLUTIONS (6 I 4) - (3 * 5) + 1 ~ ((-3 ** 3) I 2) = (3 A (4 * 2)) : 37 ((4 + 3) >= 7) II (2 && ((4 * 2) < 4)) = 1 Chapter 3 1. #!lusrlbinlperl -w # chap03ex1. pl my $target = 12; print "Guess my numberl\n"; print "Enter your guess: "; my $guess; while ($guess = <STDIN>) { 2. if ($target == $guess) { print "That's it! You guessed correctlyl\n"; last; elsif ($guess > $target) { print "Your number is more than my number\n"; elsif ($guess < $target) { print "Your number is less than my number\n"; print "Enter your guess: "; #llusrlbinlperl -w # chap03ex2.pl for (my $i = 1; $i <= 10; $i++) { print "$i square is: ", $i*$i, "\n";

4 388 APPENDIX EXERCISE SOLUTIONS 3. # chap03ex3.pl for (my $i = 1; $i <= so; $i++) { if ($i % s == o) { print "$i is evenly divisible by 5\n"; Chapter 4 1. # chap04exl.pl = (2, 4, 6, 8); foreach (@a) { print "$_ ** 2 = ", $_ ** 2, "\n"; foreach { print "$_ ** 2 = " -,, $ ** 2 "\n" 3. Here is a program that illustrates the answer to this question. # chap04ex3.pl = ( 'a a'. ' bb' ) ; print "first array:\n"; print "@a\n";

5 APPENDIX EXERCISE SOLUTIONS = (' ao' ' bg' ) ; print " \n"; print "second array:\n"; print "@a\n"; Chapter 5 1. # chap05ex1.pl my %hash = ( scalar => 'dollar sign', array => 'at sign', hash => 'percent sign' ); foreach (sort keys %hash) { print "$_: $hash{$_\n"; 2. # chap05ex2.pl my %phonenumbers = John => ' ', Sue => ' ', Larry=> ' ', Moe => ' ' ); print "enter name: "; while (<STDIN>) { chomp; if (exists $phonenumbers{$ ) { print "$_has the phone number: $phonenumbers{$_\n";

6 390 APPENDIX EXERCISE SOLUTIONS else { print "$_is not in the phone book\n"; print "enter name: "; 3. # chaposex3.pl my %jokes = Java =>"None. Change it once, and it's the same everywhere.", Python => "One. He just stands below the socket and the world " "revolves around him.", Perl => "A million. One to change it, the rest to try and do it in " "fewer lines.", C =>'"CHANGE?!!"' ); print "enter programming language: "; while (<STDIN>) { chomp; if (exists $jokes{$_) { print "How many $_ programmers does it take to change a lightbulb?\n ; sleep 2; print $jokes{$_, "\n"; else { print "That language is not funny. \n"; print "enter programming language: "; Chapter 6 1. # chapo6exl.pl print "enter a number: "; chomp(my $input_num = <STDIN>);

7 APPENDIX EXERCISE SOLUTIONS 391 if {$input_num < o) { print "please enter a positive numberl\n"; else { my $result = factorial{$input_num); print "$input_num! = $result\n"; sub factorial { my $num = shift; if {$num == o) { return 1; else { my $answer = 1; foreach (2 $num) { $answer = $answer * $_; return $answer; # here is the solution using recursion - # a recursive function is a function that calls # itself sub factorial_recursive { my $num = shift; if {$num == o) { return 1; else { return $num * factorial_recursive{$num - 1); 2. # chap06ex2.pl my $number_of_seconds; prompt_user(); my ($hours, $minutes, $seconds) = secs2hms($number_of_seconds);

8 392 APPENDIX EXERCISE SOLUTIONS print "$number_of_seconds seconds is $hours hours, $minutes " "minutes and $seconds seconds"; print "\n"; sub prompt_user { print "please enter the number of seconds: "; chomp($number_of_seconds = <STDIN>); sub secs2hms { my ($h,$m); my $seconds = shift;; # defaults to $h = int($seconds/(6o*6o)); $seconds %= 60*60; $m = int($seconds/6o); $seconds %= 60; ($h,$m,$seconds); Chapter 7 1. Match "hello" followed by zero or more and any character but \n followed by "world"; or, in other words, any string that contains "hello" followed later by "world". Match one or more digits at the beginning of the string followed by one whitespace character followed by zero or more word characters followed by the end of the string. Match an uppercase letter at the beginning of a word followed by zero or more lowercase letters to the end of a word; or, in other words, match a word that begins with an uppercase letter followed by any number of lowercase letters. Match a character, remember it in \1, followed by any number of any characters but \n, followed by the character remembered. In other words, match any string with two occurrences of the same character. 2. /"\d.* \d$/ /"[\s\w]+$1 /"\5*$/ 3. # chap07ex3.pl

9 APPENDIX EXERCISE SOLUTIONS 383 while ( <>) { print if /[aeiouy][aeiouy]/i; 4. # chap07ex4.pl while (<>) { print if fa[aaeiouy]*[aeiouy][aaeiouy]*[aeiouy][aaeiouy]*$/i; Chapter 8 1. # chapo8ex1.pl open(infh, '<', 'gettysburg. txt') or die $1; open(outfh, '>', 'exlout.txt') or die $1; while (<INFH>) { next if fa\s*$1; = split; print OUTFH "$_\n" close INFH; close OUTFH; 2. # chapo8ex2.pl unless (@ARGV) = qw(filel.dat file2.dat file3.dat); print <>;

10 394 APPENDIX EXERCISE SOLUTIONS 3. # chapo8ex3.pl my $target; while (1) { print "What file should I write to? "; $target = <STDIN>; chomp $target; if (-d $target) { print "No, $target is a directory.\n"; next; if (-e $target) { print "File already exists. What should I do?\n"; print "(Enter 'r' to write to a different name, "; print "'o' to overwrite or\n"; print "'b' to back up to $target.old)\n"; my $choice = <STDIN>; chomp $choice; if ($choice eq "r") { next; elsif ($choice eq "o") { unless (-o $target) { print "Can't overwrite $target, it's not yours.\n"; next; unless (-w $target) { print "Can't overwrite $target: $!\n"; next; elsif ($choice eq "b") { if (-e "$target.old") { print "Backup $target.old exists. Overwrite it? [yin] "; my $choice = <STDIN>; chomp $choice; if ($choice ne 'y') { next; if ( rename($target, $target.".old") ) { print "OK, moved $target to $target.old\n";

11 APPENDIX EXERCISE SOLUTIONS 395 else { print "Couldn't rename file: $!\n"; next; else { print "I didn't understand that answer.\n"; next; last if open(output, '>', $target); print "I couldn't write to $target: $!\n"; # and round we go again. print OUTPUT "Congratulations.\n"; print "Wrote to file $target\n"; close OUTPUT; Chapter 9 1. # chap09ex1. pl open(fh, '<', 'exl.dat') or die$!; while (<FH>) { my $name = substr $_, o, 24; my $address = substr $_, 25, 18; my $city = substr $_, 52, 20; my $state = substr $_, 72, 2' my $zip = substr $_, ' 75, 5; print <<EOT; Record: name address city $name $address $city

12 396 APPENDIX EXERCISE SOLUTIONS state zip EOT $state $zip close FH; 2. # chap09ex2.pl while (<>) { tr/a-za-z/n-za-mn-za-m/; print; Chapter # chaploexl.pl my $dir =shift II ''; my $size= shift I I ''; die "usage: ex1.pl <din <size>\n" unless $dir and $size; chdir $dir or die "can't chdir: $!"; # first, a file glob # this gets hidden files too print "using glob:\n"; foreach (<.* *>) { if (-f $_and -s _ >= $size) { print 1 1, $_, 1 1 X (30 - length($_)), -s _, "\n",

13 APPENDIX EXERCISE SOLUTIONS 397 # now using a directory handle print "\n\nusing directory handle:\n"; opendir DH, I. I or die "opendir failed: $!"; while {$_ = readdir(dh)) { if (-f $_and -s _ >= $size) { closedir DH; print I ~,$_,I I x (30- length($_)), _,, -s "\n" Chapter #1/usr/bin/perl -w # chap11ex1. pl = qw(r N B Q K N B R); foreach (0.. 7) { $chessboard[o]->[$j = "W". $back[$_]; #White Back Row $chessboard[1]->[$j = "WP"; #White Pawns $chessboard[6]->[$j = "BP"; #Black Pawns $chessboard[7]->[$_] = "B". $back[$_]; # Black Back Row while (1) { # Print board foreach my $i (reverse (0.. 7)) {#Row foreach my $j (0. 7) { #Column if (defined $chessboard[$i]->[$j]) { print $chessboard[$i]->[$j]; elsif ( ($i % 2) == {$j % 2) ) { print".. "; else { print " "; print " "; # End of cell print "\n"; # End of row

14 398 APPENDIX EXERCISE SOLUTIONS print "\nstarting square [x,y]: "; my $move = <>; last unless ($move=~ fa\s*([1-8]),([1-8])/); my $startx = $1-1; my $starty = $2-1; unless (defined $chessboard[$starty]->[$startx]) { print "There's nothing on that square!\n"; next; print "\nending square [x,y]: "; $move = <>; last unless ($move=~ /([1-8]),([1-8])/); my $endx = $1-1; my $endy = $2-1; # detect if a piece is about to be taken if (defined $chessboard[$endy]->[$endx]) { print "\n$chessboard[$endy]->[$endx] at (", $endx + 1,,, $endy+1, ") is being taken!\n\n"; # Put starting square on ending square. $chessboard[$endy]->[$endx] = $chessboard[$starty]->[$startx]; # Remove from old square undef $chessboard[$starty]->[$startx]; 2. # chap11ex2.pl = qw(r N B Q K N B R); foreach (0.. 7) { $chessboard[o]->[$_] = "W". $back[$_]; # White Back Row $chessboard[1]->[$_] = "WP"; # White Pawns $chessboard[6]->[$_] = "BP"; #Black Pawns $chessboard[7]->[$_] = "B". $back[$_]; # Black Back Row while (1) { # Print board foreach my $i (reverse (0.. 7)) {#Row foreach my $j (0.. 7) { #Column

15 APPENDIX EXERCISE SOLUTIONS - if (defined $chessboard[$i]->[$j]) { print $chessboard[$i]->[$j]; elsif ( ($i % 2) == ($j % 2) ) { print~~. ~~; else { print II II; print II II; # End of cell print \nll; 11 # End of row print 11 \nstarting square [x,y]: "; my $move = <>; last unless ($move=- /A\s*([1-8]),([1-8])/); my $startx = $1-1; my $starty = $2-1; unless (defined $chessboard[$starty]->[$startx]) { print "There's nothing on that square 1\n"; next; print "\nending square [x,y]: "; $move = <>; last unless ($move=- /([1-8]),([1-8])/); my $endx = $1-1; my $endy = $2-1; if (defined $chessboard($endy]->[$endx]) { # can't take your own piece if (substr($chessboard($endy]->[$endx], 0 1 1) eq substr($chessboard($starty]->($startx], o, 1)) { print "\nyou can't take your own piecel\n\n"; next; # can't take a king if ($chessboard[$endy]->[$endx].~ /K/) { print "\nyou can't take a kingl\n\n"; next; # Put starting square on ending square. $chessboard[$endy]->[$endx] = $chessboard[$starty]->[$startx]; # Remove from old square undef $chessboard[$starty]->[$startx];

16 400 APPENDIX EXERCISE SOLUTIONS 3. # chap11ex3.pl my %addressbook; sub menu { print «EOT; Please make a choice: 1 add an entry 2 view an entry 3 view all entries 4 delete an entry 5 exit Your choice: EOT sub add_entry { print "Enter name: "; chomp(my $name = <STDIN>); if (exists $addressbook{$name) { print "Name alread exists in the address book!\n"; print "Address: "; chomp(my $address = <STDIN>); print "Phone: "; chomp(my $phone= <STDIN>); $addressbook{$name = { address => $address, phone => $phone ; sub view_entry { print "Enter name to view: "; chomp(my $name = <STDIN>); if (exists $addressbook{$name) { print "Address: $addressbook{$name{address\n"; print "Phone: $addressbook{$name{phone\n\n";

17 APPENDIX EXERCISE SOLUTIONS 401 else { print "$name is not in address book!\n\n") sub view_all { foreach my $name (sort keys %addressbook) { print "Name: $name\n"; print "Address: $addressbook{$name{address\n"; print "Phone: $addressbook{$name{phone\n\n"; sub delete_entry { print "Enter name to delete: "; chomp(my $name = <STDIN>); if (exists $addressbook{$name) { delete $addressbook{$name; else { print "$name is not in address book!\n\n"; while (1) { menu(); chomp(my $answer= <STDIN>); SWITCH: { $answer == 1 and add_entry(), $answer == 2 and view_entry(), $answer == 3 and view_all(), $answer == 4 and delete_entry(), $answer == 5 and exit(o); Chapter # chap12ex1. pl use Person&; last SWITCH; last SWITCH; last SWITCH; last SWITCH;

18 4lrl APPENDIX EXERCISE SOLUTIONS my $object1 = Person8->new( lastname => "Galilei", firstname => "Galileo", address occupation phone_no => => => "9.81 Pisa Apts.", "bombadier", " " ); my $object2 = Person8->new( last name => "Wall", firstname => "Larry", address => "123 Perl Ave.", occupation => "Programmer", phone_no => " " ); my $object3 = Person8->new( lastname => "Torvalds", first name => "Linus", address => "593 Linux Ave.", occupation => "Programmer", phone_no => " " ); print "There are ", Person8->headcount(), PersonS objects\n"; foreach my $person (Person8->everyone()) { print "\n", '-' x 80, "\n"; $person->printletter("you owe me money. Please pay it."); Chapter # chap14ex1.pl use CGI ':standard'; print header(), start_html('exercise 1');

19 APPENDIX I EXERCISE SOLUTIONS 403 if (param) { my $name = param('name') II ''; my $address= param('address') I I ''; my $phone = param('phone') II ''; print h1('thanks for your information!'), 'Thanks for entering the following information:', br(), $name, br(), $address, br(), $phone; open FH, '>>', '/tmp/ex1.dat'; print FH - x 80, "\n$name\n$address\n$phone\n"; close FH; else { print 2. print h1('please enter some information'), start_ form(), 'Name:, textfield(-name => 'name'), br(), Address:, textarea(-name => 'address', rows => 3), br(, 'Phone number:, textfield(-name => 'phone', br(), submit(), end_ form(); end html(; The solution to this problem is to include the changes shown previously in the section for Chapter 11, exercises 1 and 2.

20 404 APPENDIX EXERCISE SOLUTIONS Chapter # chap1sex1. pl use DBI; my($instrument, $musician); print "Enter instrument: "; chomp($instrument = <STDIN>); my $dbh = DBI->connect("DBI :mysql :musicians_db", "musicfan'!, "CrimsonKing"); die "connect failed: ". DBI->errstr() unless $dbh; # use a table join to query the instrument names my $sth = $dbh->prepare("select musicians.name FROM musicians,what_they_play,instruments WHERE instruments.instrument =? AND musicians.player_id = what_they_play.player_id AND what_they_play.inst_id = instruments.inst_id") or die "prepare failed: ". $dbh->errstr(); $sth->execute($instrument) or die "execute failed: ". $sth->errstr(); # loop through them, printing them while (($musician) = $sth->fetchrow()) { print " $musician\n"; $sth->finish(); $dbh->disconnect(); 2. # chap15ex2.pl use CGI ':standard'; use DBI;

21 APPENDIX EXERCISE SOLUTIONS - if (param()) { my $instrument= param('instrument') I I ''; print header(), start_html("musicians who play $instrument"); hl("musicians who play $instrument"); my $dbh = DBI->connect("DBI:mysql:musicians_db", "musicfan", "CrimsonKing") ; my $sth = $dbh->prepare("select name FROM musicians, what_they_play, instruments WHERE instruments.instrument =? AND instruments.inst_id = what_they_play.inst_id AND what_they_play.player_id = musicians.player_id") or die "prepare failed: " $dbh->errstr(); $sth->execute($instrument) or die "execute failed: " $sth->errstr(); my($name); while (($name) = $sth->fetchrow()) { print "$name plays the $instrument.<br>"; print end_html; else { print header(), start_html('my Favorite Instrument'), hl('select an Instrument', start_ form(), '<select name="instrument">'; my $dbh = DBI->connect("DBI:mysql:musicians_db", "musicfan", "CrimsonKing"); my $sth = $dbh->prepare("select instrument FROM instruments") or die "prepare failed: " $dbh->errstr(); $sth->execute() or die "execute failed: ". $sth->errstr(); my($instrument); while (($instrument) = $sth->fetchrow()) { print qq{<option value="$instrument">$instrument</option>;

22 406 APPENDIX EXERCISE SOLUTIONS print '</select>', br(), submit('show musician(s)'), end_ form(), end_html();

23 Index Symbols! (not) Boolean operator, 30!=(not equal to) comparison operator, 28! - (negated regex match) operator, 35 patterns not matching, 151 #(comments), 3 documenting programs, 6 #!(hash bang), 3 $ (anchor to end) escaping metacharacters, 155 $ (scalar variables) assignment(=) operator, 37 scalars, 37 $prefix naming conventions, 111 $! special variable file error, openo function, 178, 179 $#array array's last index, 95 $array accessing single array elements, 92 $_(special variables), 44 default value, 217 $1 special variable controlling buffering, 193 %prefix naming conventions, 111 & (AND) bitwise operator, 25 && (and) Boolean operator, 29 &sub_routine declaring subroutines in Perl4, 133 * (asterisk) escaping metacharacters, 155 repetition with quantifiers, 163 **(exponentiation) operator assignment(**=) operators, 39 + (plus sign) escaping metacharacters, 155 repetition with quantifiers, 163 -> (infix dereference) arrow operator ${$ref-> arrow notation, 239 matrices, 242 methods, 255 references in references, 239. (period) escaping metacharacters, 155 pattern matching at end of string, 156 I (forward slash) character regular expressions, (zero) definitions of false, 27 =(equals) assignment operator $(scalar variables), 37 ==(equals equals) comparison operator, 27 not assignment operator(=), 37 numeric comparison operators, 54 =- (regex match) operator, 35 counting character occurrences, 210 finding patterns, 151 translating a string, 210 => (list separator) operator, 35 creating hashes, 112 dynamic CGI program, 335 named parameters, 146? (question mark) escaping metacharacters, 155 repetition with quantifiers, 162 ::(colons) translating into directory separators, array prefix character see under arrays [] square brackets escaping metacharacters, 155 patterns, 158 references to anonymous arrays, 232 modifying referenced array, 238 \ (backslash character) escape sequences, 17 double quoted string, Wmdows, 178 escaping metacharacters, 155 operators, 35 \ (reference of) operator creating reference for existing variable, (anchor), (XOR) bitwise operator, 26 II negating character class [], 158 _(underscore) default filehandle for file tests,

24 - (backquote) character backquotes,225,226 { curly brackets escaping metacharacters, 155 hashes, 114 references in references using -> shorthand, 239 references to anonymous arrays modifying referenced array, 237 references to hashes, 238 anonymous hashes, 232 repetition with quantifiers, 164 statement blocks, 7 subroutines, 128 I (OR) bitwise operator, 26 either-or operator, Regex, 161 I character escaping metacharacters, 155 pipes, 194 II (or) Boolean operator, 30 - (NOT) bitwise operator, 26 <(less-than) comparison operator, 28 < (read mode) open() function, 180 <=> spaceship comparison operator, 29 «(left shift) operator, 35 <>(diamond) see diamond(<>) > (greater-than) comparison operator, 28 > (write mode) open() function, 180» (append mode) open() function, 181» (right shift) operator, 35 A \a (alarm) escape sequence, 8 <a> tags CGI.pm module generating, 327 a() method CGI.pm module, 327 providing attributes for, 330 abstraction encapsulation,256,257 accessor methods methods, 271 Person class, 282 shift() function, 272 action= attribute CGI scripts processing form data, 331 addition(+) operator, 22 assignment(+=) operator, 39 address book example, trees, 247 adding another level, 249 deleting data, 249 extracting data, 249 making new entries, 248 printing out data, 248 alarm (\a) escape sequence, 8 alphabetical order finding character's ASCII value, 33 anchors common errors writing Regexes, 174 patterns, 155, 156 AND (&) bitwise operator, 25 AND keyword WHERE clause, 361 and (&&) Boolean operator, 29 anonymous arrays accessing referenced array, 234 actual memory location, 235 creating reference to, 232, 234 anonymous data references creating. 230 anonymous hashes creating reference to, 232 anonymous references counting. 242 Apache configuration troubleshooting CGI scripts, 318 creating CGI directory, 316 errorlogffie troubleshooting CGI scripts, 318 append mode (») open() function, 181 arguments, 21 open() function, 177 parentheses 0 for, 7 arguments, subroutines, 133 default values, 145 named parameters providing, 146 named parameters, 145 passing arrays as, 144 passing by reference, 141 passing into subroutines, passing lists, 143 stopping functions modifying, 142 $ARGV special variable, 188 arithmetic operators, 22 array functions, 104 pop() function, 105 push() function, 105 reverse() function, 104 shift() function, 107

25 409 sort() function, 108 unshift() function, 107 arrays, $#array, 95 $array, prefix character, 87 naming conventions, array, 186 command line arguments, 186 diamond(<>), 186, 187 displaying array contents, 186 mehandles, writing to rues, 191 my() function, 186 passing arguments into subroutines, 136 push() function, 188 shift() function, 143, 187 storing into variables, 186 use strict statement, accessing multiple elements, package variable, array, 262 changing, 263 lib pragma, using, 264 require statement using, passing arguments into subroutines, 133 accessing data in referenced, 239 accessing multiple elements, 97 accessing single elements, 91 using [] to identify, 92 adding elements to, 91 array elements accessing in anonymous array, 236 array functions, 104 array index, 93 array slice accessing multiple elements, 97 assigning in scalar context, 90 assigning values, 87, 112, 113 counting occurrences in hash, 123 declaring arrays, 88 double-quoted strings, 89 foreach loop, 68, 99 hashes assigning values from, 113 assigning values to, 112 compared, 111 lists, 87 looping through, 95 left to right, 97 naming conventions, 87,111 print() function, 89 references to accessing data in, 240 anonymous arrays, 232 Regexes, common errors writing, 174 stacks, 105 ASCII value finding character's ASCII value, 34 assignable lists, 86 assigning values arrays, 87 hashes, 112 lists, 78 assignment (=, +=,...) operators $(scalar variables), 37 autodecrement (--)operator, 39 autoincrement (++)operator, 39 multiple assignments, 41 operator precedence, 38 associative arrays see hashes attributes action= attribute, 331 class attributes, 273 creating classes naming/ storing attributes, 267 described, 254 get-set methods, 273 providing attributes for classes, 269 providing for CGI.pm methods, 330 a() method, 330 autodecrement ( ) operator, 39 auto increment ( ++) operator, 39 autovivification automatic creation of references, 243 chessboard example, matrix, 244 B \b (word boundaries) pattern matching, 160 \b (backspace) escape sequence, 8 backquotes C) character, 225, 226 backreferences Regular expressions, 165, 174 backslash character escape sequences, 17 double quoted string, Wmdows, 178 escaping metacharacters, 155 operators, 35 backspace (\b) escape sequence, 8 bareword warning, 16 base class see superclass Benchmark module standard modules, 302 bidirectional pipes piping in and out of a process, 198 binary numbers, 15 conversion to strings, 20,21 errors using, 16 binary system, 9

26 410 INDEX bits, 9 bitwise operators, 24 AND(&) operator, 25 NOT H operator, 26 OR (j) operator, 26 significance of bits, 25 XOR (A) operator, 26 blank line after header troubleshooting CGI scripts, 318 bless() function blessing again, 267 creating classes, 265 syntax, 265 blocks statement blocks, 7 body, subroutines, 130 Boole, George, 27 Boolean logic, 27 if statements, 53 Boolean operators, 29 and(&&) operator, 29 not (!) operator, 30 operator, 30 xor (exclusive or) operator, 30 boundaries, words pattern matching, 160 breaking the loop looping constructs, 71 buffering controlling output, 193 controlling using $1, 193 bugs, lo Bunce, Tim, 365 bundles c Bundle::libnet, 312 Bundle::LWP, 31i documentation, 312 CPAN module helping download, 311 detecting package dependencies, 311 canonpath() function File::Spec module, 301 case sensitivity i for insensitive, 153 MySQL server, 352 pattern matching, 153 catdir() function File::Spec module, 301 catfile() function File::Spec module, 301 CGI (Common Gateway Interface), creating CGI directory, 316 generating HTML, 320 processing form data, 330 webserver access, 316 writing CGI programs, 316 exported environment variables, 319 hello world program, 317 CGI scripts, 315 chessprogram, developing CGI script with DBI, dynamic CGI program, 333 example, 334 param() method, 332, 333 start_form() method, 335 textfield() method, 335 environment variables displaying,319,320 exported, 319 generating HTML web page with CGI.pm, 324 without CGI.pm, 322 state, 335 static CGI program, 332 troubleshooting perlmonks website, 318 why use Perl, 315 writing, 316 blank line after header, 317,318 hello world program, 317 permissions, 317 troubleshooting, 318 CGI.pm module, 322 example using, 326 generating <a> and <p> tags, 327 method types, 329 methods a() method, 327 calling methods, 328 dynamic CGI program using, 335 generating more than one tag, 329 generating one tag, 330 header() method, 326 invoking, 329 named parameters, 329 po method, 327 print() function, 328 start_html() method, 326, 329 processing form data, 322 tags, generating, 326 CGI::Carp module chess CGI program, 344 character classes [] negating, 158 patterns, 158 predefined character classes, 159 sequences of characters, 159 characters escaping metacharacters, 155 chdir() directory function, 219 chess CGI program, 335

27 411 chessboard example, matrix, 242 autovivification, 244 making moves, 244, 247 printing checkered effect, 246 setting up board, 244, 246 chmod command, 4 chmod() directory function, 222 chomp() function passwords, 57 standard input <STDIN>, 47 user/runtime specified patterns, 155 while loop, 66 chop() function standard input <SID IN>, 48 class attributes, 273 Person class, 282 classes attributes, providing for classes, 269 constructors, 268 creating, 264 bless() function, 265 constructors, 268 get -set methods, 273 inheritance, 269 ref() function, 265 storing attributes, 267 described, 255 inheritance, 256 instances, 255 interfaces, 256 methods, 255 methods, creating, 271 class attributes, 273 get-set methods, 273 privatizing methods, 277 utility methods, 279 naming conventions, 256 objects, 255 constructors, 257 destructors, 258 static data, 255 static methods, 255 subclass, 257 superclass, 257 close() FTP method, 261 close() function, 178 Cohen, Max patterns, 149 columns see fields comma operator (arguments), 35 command line interface (Cil), MySQL, 352 commands capturing output using backquotes, 225 flexible use of command line arguments, 298 commands, list of CREATE DATABASE, 353 CREATE TABLE, 353 DELETE, 382 DESCRIBE, 354 GRANT,354 INSERT,355 mysqlshow, 351 REPLACE, 383 SELECT,358 UPDATE,382 USE,353 comments,3 documenting programs, 6 comparison operators, 27 equals(==), 27 greater-than(>), 28 less-than(<), 28 not equal to(!=), 28 spaceship operator ( <=>), 29 string comparisons, 33 true or false, 27 complex data structures using references for, 242 matrices, 242 trees, 247 concatenation (.) operator assignment(.=) operators, 39 concatenation string operator, 31 concurrency relational databases, 347 conditional operators if... else statements, 58 if... elsif statements, 59 if statements, 52 introduced, 35 logical operators, 58 unless statement, 61 connect() method, DBI module, 366 constants, 13 constructors class constructors, 257 creating classes, 268 described, 257 Person class, 282 content type CGI scripts generating HTML, 320 troubleshooting CGI scripts, 318 conversions octal, hex and binary; 20 strings and numbers, 20 rules, 33 Conway, Damian Object Oriented Perl, 253

28 412 INDEX counting hashes,122,197 CPAN (Comprehensive Perl Archive Network), 305 accessing CPAN shell, 309 CSPAN confusion, 258 detecting package dependencies, 311 modules, finding to installihg, 308 installing manually, 308 installing with PPM, 307 modules available at, 287 search engine, 306 standard module doesn't exist, 312 using existing modules, 306 CREATE DATABASE command, 353 CREATE TABLE command, 353 curly brackets { escaping metacharacters, 155 hashes, 114 references in references, 239 references to anonymous arrays, 237 references to hashes, 238, 232 repetition with quantifiers, 164 statement blocks, 7 subroutines, 128 currency conversion program, 46 current directory, 262 cwdo FfP method, 260 D d file test, 199 -doption debugging, 10 /dmodifier removing spaces in strings, 210 \d (digit 0-9) predefined character classes, 159 \D (any nondigit) predefined character classes, 159 data data patterns, Regexes, 149 data types, 13 extracting from MySQL database, 358 reference count, 241 data structures using references for complex, 242 visual representation of, 295 database commands CREATE DATABASE, 353 CREATE TABLE, 353 DELETE,382 DESCRIBE, 354 GRANT,354 INSERT,355 REPLACE, 383 SELECT, 358 UPDATE,382 USE,353 database handler DBI connecto method, 366 databases creating a database, 352 extracting data from, 358 indexing, 383 Data::Dumper module choosing output variable name, 296 standard modules, 295 DBD (Database Driver) modules DBI (Database Independent) module, 365 DBD::mysql module installing, 365 DBI (Database Independent) module, 347, 365 database handler, 366 DBD (Database Driver) modules, 365 developing CGI script with, DSN (data source name), 366 executing SQL query with DBI, 367,369 installing, 365 joins, 374 methods connecto method, 366 disconnecto method, 367 errstro method, 367 executeo method, 368 fetchrowo method, 368 finisho method, 368 prepareo method, 368 Perl connecting to MySQL, 366 placeholders, 372 state handler, 368 debugging visual representation of data structures, 296 declaring subroutines, 128, 130 default values subroutine arguments, 145 definedo function if statements, 57 definite loops, 63 del command (Wmdows), 220 DELETE command, 382 deleteo FfP method, 260 deleteo hash function, 120 removing elements from hash, 114 delimiters Regexes changing, 170 choosing your own, 19 dereferencing accessing data in references, 233, 234 assigning values to references, 241 undefcommand,242

29 413 derived class, 257 DESC (descending) qualifier ORDER BY clause, 362 DESCRIBE command, 354 destroy() method object destruction, 281 destructors described, 258 object destruction, 281 references, 276 Devicelnfo() function Win32::Sound module, 304 Devices() function Wm32::Sound module, 304 diamond(<>), $ARGV special variable, special array, 186, 187 command line arguments, 184 data file on command line, 185 description, 158, 184 file globbing, 215 how it works, 187 no command line arguments, 184 opening and closing file, 185 reading file in list context, 188, 195 array oflast x lines read, 189 reading from <STDIN>, 184 summary, 204 working with trill, 211 die() function chess CGI program, 344 file error, open() function, 178 program errors, 49 die() method, DBI module executing SQL query with DBI, 370 digit (\d) predefined character, 159 non-digit (\D), 159 directives use warnings, 5 directories changing directory, 219 effect on shell, 219 example, 222 character indicating, 218 creating (making), 221 example, 222 current directory, 262 deleting (removing), 222,297 directory handles, 218 directory separators translating colons (::) into, 288 listing and examining contents, 216 listing example, 222 opening directory, 218 reading directory, 218, 219 setting up, 3 testing if file is a directory, 217 traversing directory trees, 297 directory functions chdir() function, 219 chmod() function, 222 mkdir() function, 221 opendiro function, 218 readdiro function, 218 rmdiro function, 222 disconnect() method, DBI module, 367 division (/) operator, 22 assignment(/=) operators, 39 do.. until loop, 69 do.. whileloop,69 do statement, 261 require statement compared, 262 documentation documenting programs, 6 online documentation, 290 double-quoted strings, 17 array variables, 89 lists, 79 qq/1, 19 quotes inside quotes, 18 variable processing, 17 downloading packages detecting package dependencies, 311 DSN (data source name) connect() method arguments, 366 debugging, 10 E -e file test, 199 \E (end of pattern) escaping metacharacters, 156 each() function hash functions, 119 piping out to a process, 198 editors choosing a text editor, 2 either-or operator Regular expressions, 161 emacs web reference for, 3 empty list, 77 empty strings definitions offalse, 27,28 encapsulation, 256 class constructors, 257 end of file characters Unix and Windows, 211 end of pattern (\E), 156 $ENV {HOMEIPATHIUSER, 213 %ENVhash, %ENY, CGI scripts, 319

30 414 INDEX environment variables CGI scripts exporting, 319 inherited from shell, 213 equal to (eq) string operator, 34 equals(=) assignment operator $(scalar variables), 37 equals equals(==) comparison operator, 27 not assignment operator(=), 37 numeric comparison operators, 54 errors bareword warning, 16 chess CGI program, 344 die() function, 49 syntax error, 16 writing into log files, 292 errstr() method, DBI module, 367 executing SQL query with DBI, 368 escape sequences, 8 \a (alarm), 8 \b (backspace), 8 \n (newline), 4, 8 \r (carriage return), 8 \t (tab), 8 \x (Unicode character), 8 backslash character, 17 strings, 17 tab representation, 17 escaping metacharacters, 155 evaluating statements short -circuited evaluation, 63 exclusive OR (") bitwise operator, 26 exclusive OR (xor) Boolean operator, 30 executability character indicating executable, 218 file tests (-x), 199 testing if file is executable, 217 execute() method, DBI module executing SQL query with DB I, 368, 370 using placeholders, 373 using placeholders and joins, 37 4 executing a program programming, 2 system() function, 223 exercise solutions chapter 1, 385 chapter2, chapter 3, chapter 4, chapter 5, chapter6, chapter7, chapter8, chapter9, chapter 10, 396 chapter11, chapter 12, 401 chapter14, chapter 15, 404 exists() hash function, 120 exit() function, 48 if statements, 61 numeric comparison operators, 55 exponentiation (**) operator, 23 negative numbers, handling, package variables, 289 %EXPORT_TAGS hash, 290 Exporter module, 288 import() subroutine, 289 using in logging module, 293 expression modifiers, 62 foreach loop, 104 looping constructs, 70 F -f file test, 199 \f (form feed) predefined character classes, 159 false, 27 fetchrow() method, DBI module executing SQL query with DBI, 368, 370 <FH> see filehandles fields creating database table, 353 relational databases, 348 showing all fields, 354 file functions chmod() function, 222 close() function, 178 link() function, 220 open()function,177 readlink() function, 221 rename() function, 203, 220 symlinko function, 220 unlink() function, 220 file globbing, reading from file glob, 215 file slurp reading file in list context, 188, 195 file tests checking status before opening, 199 directory handle, using, 218 executability, 199 file exists (-e), 199 examples, 199,201,202 file glob, using, 216 file name is directory name (-d), 199 example, 201,202 file test operators, 199 ownership (-o), 199 example, 203

31 415 perldoc perlftmc, 199 permissions, 200 plain file (-f), 199 readability (-r), 199 example, 202 size ( -s, -z), 199 unexpected response example, 201 writability (read-only) (-w), 199, 200 example, 200, 202 filehandle argument, open() function, 177 filehandles, closing, 179 default filehandle for file tests, 217 my function, 178 pipes, 194 piping out to a process, 198 print() function, 190 reading file in list context, 188 reading file in scalar context line by line until EOE 181 printing with line number, 181 reading from a pipe, 195 summary, 204 writing to files, 190 <STDIN> standard input, 177 filename argument, open() function, 177 specifying full path, 178 filenames writing portable programs, 301 files deleting from disk, 220 deleting useless files program, 298 do statement, 261 directory, testing if file is a, 217 executing/running, 3, 4 making executable, 4 testing if executable, 217 file globbing, 215 file tests, , 217 hard link, creating, 220 ownership testing if file is owned, 217 printing file size, 217 reading, testing if can be read, 217 renaming, 220 example, 222 require statement, 262 stat of the file, 217 symbolic (soft) link, creating, 220 example, 221 reading, 221 transfer to and from FTP server, 258 use statement, 263 writing to, testing if can be written, 217 File::Find module find() method, 297 standard modules, 297 wanted() subroutine, 297 File::Spec module canonpath() function, 301 catdir() function, 301 catfile() function, 301 documentation, 302 path() function, 301 splitdir() function, 301 splitpath() function, 301 standard modules, 301 trnpdir() function, 301 find() method, File::Find module, 297 finish() method, DBI module, 368 finite loops, 63 flags Getopt::Long module, 300 Getopt::Std module, 298 floating point numbers, 15 flock() function locking files, 292 flow charts, 51 if statement, 51 loops, 52 for loop, 68 arrays, looping through, 95 foreach loop, 68 arrays, looping through, 97 arrays, processing, 99 expression modifiers, 104 referenced arrays, 235 traversing trees, 250 fork() function, 226 form data CGI scripts processing, 330 action= attribute, 331 CGI.pm,322 listing parameters, 332 returning parameter value, 332 simple form example, 331 param() method, 332 widgets, 330 form feed (\f) character, 159 Format() function Wm32::Sound module, 304 forward slash (!) character regular expressions, 151 FTP methods, 260 FTPservers transferring files, 258 fullname() method Person class, 282 utility methods, 280 fully qualified variable names, 139

32 416 INDEX functions G see also subroutines array functions, described, 127 directory functions, file functions, 177, 178, hash functions, invoking,292 list functions, 78, 81 parentheses 0 for arguments, 7 string functions, subroutines compared, 128 system() function, 223 I g (global) modifier, Regexes, 171 get methods, 254 get() FfP method, 260 get() method visiting remote web sites, 311 get-set methods, 273 getopts() method, Getopt::Std module, 299 Getopt::Long module standard modules, 300 Getopt::Std module getoptso method, 299 standard modules, 298 getprinto method visiting remote web sites, 312 getpwent() function, 226 getstore() subroutine visiting remote web sites, 312 global variables, 41, 137 scope, 137 goto statement looping constructs, 76 GRANT command, 354 grave character see backquote (') character greater than (gt) string operator, 34 greater than or equal to (ge) operator, 34 greater-than(>) comparison operator, 28 H hashbang,3 hash functions, 117 delete() function, 120 each() function, 119 exists() function, 120 keys() function, 117 reverse() function, 122 values() function, 118 hash() session method, 260 hashes, accessing data in referenced, 240 address book example, trees, 248 arrays compared, 111 assigning values from an array, 112 to an array, 113 counting, 197 creating classes providing attributes, 270 curly brackets{, 114 delete() function, 114 elements adding,114 changing, 114 checking existence, 120 removing, 114, 120 examples using, 121 counting occurrences in array, 122 creating readable variables, 121 reversing information, 121 functions, 117 hash keys, 112 key/value pairs, 112 listing keys, 117 listing pairs, 119 listing values, 118 list context, 115 list separator(=>) operator, 112 my function, 114 named parameters, 146 naming conventions, 111 phone book comparison, 111 references to anonymous hashes, 232 references to hashes, 238 scalar context, 116 sort order, 111 use strict statement, 114 values, 112 working with, 113 head() method visiting remote web sites, 312 headcounto method, 273 header() method CGI.pm module, 326 developing CGI scripts, 379 helloworld.pl, 3 here-documents, 20 generating HTML with CGI.pm, 325 hex() function conversion to strings, 21 hexadecimal numbers, 15 conversion to strings, 20 errors using, 16 hexadecimal system, 9 recognizing numbers as hex, 10 HTML CGI scripts generating, 320 CGI.pm,322

33 417 with CGI.pm, 324 without CGI.pm, 322 chess CGI program, 345 HTTP header writing CGI scripts, 317 i for insensitive case sensitivity, patterns, 153 if statements, Boolean logic, 53 curly braces around statements, 52 defined() function, 57 developing CGI scripts, 380 exit() function, 61 expression modifiers, 62 flow charts, 51 if... else statements, 58 if... elsif statements, 59 logical operators, 58 numeric comparison operators, 54 short-circuited evaluation, 63 string comparison operators, 56 syntax, 52 import() subroutine, 288 module prepared to export, 289 <IN> list context filehandles, writing to files, 191 indefinite loops, 63 file tests example, 202 indentation, 7 index() string function, 206 indexes array index, 93 databases, 383 indexing into strings, 205 infinite loops, 66 looping constructs, 63 infix dereference (->) operator ${$ref-> arrow notation, 239 matrices, 242 methods, 255 references in references, 239 inheritance, 256 creating classes, 269 init() method private methods, 279 INSERT command, 355 instances of classes, 255 integers, 14 handling large numbers, 14 interfaces, 256 interpolation user/runtime specified patterns, 154 variable interpolation, 44 interpreter location of interpreter, 3 Unix users, 4 interpreting code text inside quotes, 4 invoking subroutines, 129 iteration foreach loop processing arrays, 100 modifying iterator value, 101 J join() function Regular expressions, 173 joins K DBI module using joins, 374 SELECT command, MySQL, 364 selecting without joins, 363 key/value pairs creating readable variables, 121 hashes, 112 piping out to a process, 198 keyboard standard input <STDIN>, 46 keys creating database table, 353 relational databases, 348 keys() hash function, 117 keywords avoiding use as variable names, 6 kill() function, 226 Kleene, Stephen Regular expressions, 150 L last keyword looping constructs, 71 last statement loop labels, 7 4 leo function, 198 left shift ( «) operator, 35 length() string function, 206 less than (It) string operator, 34 less than or equal to (le) operator, 34 less-than(<) comparison operator, 28 lexical variables/scope declaring arrays, 88 my function, 41, 140 scope, 137, 140 scoping variables, 41 variables, 41 array using, 264 libwin32 modules, 304

34 418 link() file function, 220 links renaming files, 220 using functions in Unix/Wmdows, 220 list context, 90 capturing output using backquotes, 225 example, 226 hashes, 115 print() function, 116 reading file in, 188 reading from file glob, 215 list functions print() function, 78, 84 reverse() function, 81 list separator(=>) operator, 35 creating hashes, 112 dynamic CGI program, 335 named parameters, 146 lists, accessing values, 83, 84 groups of values, 86 multiple values, 85 arrays,87 assignable lists, 86 assigning values, 78 double-quoted strings, 79 empty list, 77 foreach loop, 68 list slices, 85, 87 mixing strings, numbers and variables, 78 parentheses(), 78 passing as arguments, 143 qw II, creating with, 80 ranges, 81,87 single-quoted strings, 80 literal, 13 localhost, 316 localtime() function, 224 CGI scripts generating HTML, 323 locking files flock() function, 292 log files/levels, 291 logical operators, 58 login() FfP method, 260 which login() to use, 259 looping constructs, arrays, looping through, 95 breaking the loop, 71 controlling the loop, 71 definite loops, 63 do.. until loop, 69 do.. while loop, 69 expression modifiers, 70 finite loops, 63 flow charts, 52 for loop, 68 foreach loop, 68 goto statement, 76 indefinite loops, 63 file tests example, 202 infinite loops, 63 last keyword, 71 last statement, 7 4 loop control variable, 69 loop labels, 7 4 next statement, 72 redo statement, 73 reexecuting the loop, 73 until loop, 67 while loop, 63 piping out to a process, 198 lowercase leo function, 198 Is() FfP method, 260 M lm (multiple lines) modifier, Regexes, 171 Macllroy, Doug pipes, 194 matchtest.pl user/runtime specified patterns, 154, 155 matrices -> syntax, 242 chessboard example, 242 making moves, 244, 247 setting up board, 244, 246 using references, 242 memory Regular expressions, 165 metacharacters quantifiers, 162 Regular expressions, 155 common errors writing, 17 4 table summarizing, 164 methods accessor methods, 271 calling methods (->), 255 CGI.pm module, 329 class methods, 255 classes, 255 creating methods for classes, 271 class attributes, 273 get-set methods, 273 privatizing methods, 277 utility methods, 279 described, 254 FfP methods, 260 get methods, 254 get-set methods, 273 invoking, 255 private methods, 277

35 419 same name, different class, 256 set methods, 254 static methods, 255 subroutines, 255 utility methods, 279 mirror() method visiting remote web sites, 312 mkdir command, 3 mkdir() directory function, 221 mode argument, open() function, 177, 178 modifiers /d (delete), 210 Regexes, 171 modules, see also packages bundles, 311 Bundle::libnet, 312 Bundle::LWP, 311 CGI.pm module, 322 CPAN module, 308 CPAN repository, 305 creating a non-00 module, 290 Database Independent (DBI) module, 347 DBD::mysql module installing, 365 detecting package dependencies, 311 Exporter module, 288 finding and downloading, 308 import() subroutine, 288 installing modules using CPAN, 308 installing modules with PPM, 307 libwin32 modules, 304 log levels, 291 naming conventions, 288 use of.pm extension, 315 online documentation, 290 package hierarchies, 288 package relationship, 288 reasons for using, 287 standard modules, 295 flexible use of command line arguments, 298 network bundle, 312 remote web sites, 311 remote web sites bundle, 311 sound subsystem, 304 storing information in Registry, 305 testing and timing code, 302 traversing directory trees, 297 using long flags, 300 visual representation of data structures, 295 writing portable programs, 301 standard modules list Benchmark module, 302 Data::Dumper module, 295 File::Find module, 297 File::Spec module, 301 Getopt::Long module, 300 Getopt::Std module, 298 list of modules in Perl distribution, 295 Win32::Sound module, 304 Wm32::TieRegistry module, 305 modulo/modulus (%) operator assignment (%=) operators, 39 operator precedence, 24, 36 multiplication (*) operator, 22 assignment(*=) operators, 39 mvcommand renaming files, 220 my() function $ARGV special variable, special array, 186 address book example, trees, 248 chess CGI program, 339 declaring arrays, 88 declaring hashes, 114 executing SQL query with DBI, 371 filehandles, 178 lexical scope, 140 lexical variables, 41 use strict statement, 43 MySQL commands CREATE DATABASE, 353 CREATE TABLE, 353 DELETE,382 DESCRIBE, 354 GRANT,354 INSERT,355 REPlACE, 383 SELECT,358 UPDATE,382 USE,353 MySQL database connecting to, 366 executing SQL query with DBI, 367 extracting data, 358 selecting all fields, 358 selecting some fields, 358 selecting some rows, 359 inserting new rows, 355 logging in/ out, 355 non-root user, creating, 354 ordering selected rows, 361 reversing the order, 362 preparing to use, 353 showing all fields, 354 table joins, selecting using, 364 table, creating, 353

36 420 EX MySQL server case sensitivity, 352 choosing SQL server, 350 command line interface (CU), 352 creating a database, 352, 353 installation, 350 testing, 351 root user, protecting, 351 mysqlshow command, 351 N \n (newline character), 4, 8 predefined character classes, 159 named parameters, 145 CGI.pm module methods, 329 naming conventions $ prefix, 111 %prefix, prefix, 111 arrays, 87, 111 class names, 256 hashes, 111 modules, 288 packages, 140 programming, 140 scalars, 111 subroutines, 128 variables, 6, 44 variables in packages, 138 nedit web reference for, 3 negated regex match (!-) operator, 35 patterns not matching, 151 negating (A) character class[], 158 negative numbers unary minus operator, 24 Net::FfP module transferring files to/from server, 258 new() method class constructors, 259 object constructors, 257 newline character (\n), 4, 8 predefined character classes, 159 next statement loop labels, 7 4 looping constructs, 72 non-digit (\D) predefined character, 159 non-whitespace (\S) predefined character, 159 non-word(\ W) predefined character, 159 normalization relational databases, 350 NOT (-) bitwise operator, 26 not (!) Boolean operator, 30 not equal to(!=) comparison operator, 28 not equal to (ne) string operator, 34 NotePad text editor, 3 numbers, 14 binary, 15 conversion into strings, 20 converting strings into numbers, 33 floating point, 15 hexadecimal, 15 integers, 14 numeric comparison operators, 54 octal, 15 predefined character classes, 159 string comparison operators, 34 numeric operators, 22 comparing strings, o file test, 199 object destruction destroy() method, 281 object -oriented programming, 253 creating a non-00 module, 290 value in Perl, 283 objects accessormethods,271 classes, 255 described, 253 car analogy, 256 object constructors, 257 object destructors, 258 explicit destruction, 281 implicit destruction, 281 perlobj, quote from, 260 what programmers need to know, 256 oct() function conversion to strings, 21 octal numbers, 15 conversion to strings, 20 errors using, 16 octal system, 9 one-to-one correspondences see hashes online documentation perldoc program, 290 open() function append mode(»), 181 arguments, 177 filehandles, writing to files, 191 modes (read/write/append), default, 180 opening files, 177 pipes, 194 piping out to a process, 198 read mode(<), 180 return value, 204 write mode(>), 180

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS

Beginning Perl. Third Edition. Apress. JAMES LEE with SIMON COZENS Beginning Perl Third Edition JAMES LEE with SIMON COZENS Apress About the Author... About the Technical Reviewers Acknowledgements Suitrod yetion «. xvi xvii xviii «xix. Chapter 1: First Steps in Perl..

More information

1. Introduction. 2. Scalar Data

1. Introduction. 2. Scalar Data 1. Introduction What Does Perl Stand For? Why Did Larry Create Perl? Why Didn t Larry Just Use Some Other Language? Is Perl Easy or Hard? How Did Perl Get to Be So Popular? What s Happening with Perl Now?

More information

PERL Scripting - Course Contents

PERL Scripting - Course Contents PERL Scripting - Course Contents Day - 1 Introduction to PERL Comments Reading from Standard Input Writing to Standard Output Scalar Variables Numbers and Strings Use of Single Quotes and Double Quotes

More information

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295 Perl Scripting Duration: 4 Days Price: $2295 Discounts: We offer multiple discount options. Click here for more info. Delivery Options: Attend face-to-face in the classroom, remote-live or on-demand streaming.

More information

Hands-On Perl Scripting and CGI Programming

Hands-On Perl Scripting and CGI Programming Hands-On Course Description This hands on Perl programming course provides a thorough introduction to the Perl programming language, teaching attendees how to develop and maintain portable scripts useful

More information

Pathologically Eclectic Rubbish Lister

Pathologically Eclectic Rubbish Lister Pathologically Eclectic Rubbish Lister 1 Perl Design Philosophy Author: Reuben Francis Cornel perl is an acronym for Practical Extraction and Report Language. But I guess the title is a rough translation

More information

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007 Perl and Python ESA 2007/2008 Eelco Schatborn eelco@os3.nl 27 September 2007 ESA: Perl Vandaag: 1. Perl introduction 2. Basic Perl: types, variables, statements,... 3. Object Oriented Perl 4. Documentation

More information

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1 CSCI 4152/6509 Natural Language Processing Perl Tutorial CSCI 4152/6509 Vlado Kešelj CSCI 4152/6509, Perl Tutorial 1 created in 1987 by Larry Wall About Perl interpreted language, with just-in-time semi-compilation

More information

Perl. Interview Questions and Answers

Perl. Interview Questions and Answers and Answers Prepared by Abhisek Vyas Document Version 1.0 Team, www.sybaseblog.com 1 of 13 Q. How do you separate executable statements in perl? semi-colons separate executable statements Example: my(

More information

Perl (5 Days Content)

Perl (5 Days Content) Perl (5 Days Content) Pre-requisites: Knowledge of any programming language ( C / C++ / Shell Scripting) Objective of the Course: The participants should be in a position to understand Perl Scripts written

More information

A control expression must evaluate to a value that can be interpreted as true or false.

A control expression must evaluate to a value that can be interpreted as true or false. Control Statements Control Expressions A control expression must evaluate to a value that can be interpreted as true or false. How a control statement behaves depends on the value of its control expression.

More information

What is PERL?

What is PERL? Perl For Beginners What is PERL? Practical Extraction Reporting Language General-purpose programming language Creation of Larry Wall 1987 Maintained by a community of developers Free/Open Source www.cpan.org

More information

CERTIFICATE IN WEB PROGRAMMING

CERTIFICATE IN WEB PROGRAMMING COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING

More information

9.1 Origins and Uses of Perl

9.1 Origins and Uses of Perl 9.1 Origins and Uses of Perl - Began in the late 1980s as a more powerful replacement for the capabilities of awk (text file processing) and sh (UNIX system administration) - Now includes sockets for communications

More information

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St.

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St. Introduction to Perl c Sanjiv K. Bhatia Department of Mathematics & Computer Science University of Missouri St. Louis St. Louis, MO 63121 Contents 1 Introduction 1 2 Getting started 1 3 Writing Perl scripts

More information

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug Outline CS3157: Advanced Programming Lecture #2 Jan 23 Shlomo Hershkop shlomo@cs.columbia.edu Feedback Introduction to Perl review and continued Intro to Regular expressions Reading Programming Perl pg

More information

UNIX Shell Programming

UNIX Shell Programming $!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...

More information

(Refer Slide Time: 01:12)

(Refer Slide Time: 01:12) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl

More information

Scripting Languages Perl Basics. Course: Hebrew University

Scripting Languages Perl Basics. Course: Hebrew University Scripting Languages Perl Basics Course: 67557 Hebrew University אליוט יפה Jaffe Lecturer: Elliot FMTEYEWTK Far More Than Everything You've Ever Wanted to Know Perl Pathologically Eclectic Rubbish Lister

More information

Beginning Perl. Mark Senn. September 11, 2007

Beginning Perl. Mark Senn. September 11, 2007 GoBack Beginning Perl Mark Senn September 11, 2007 Overview Perl is a popular programming language used to write systen software, text processing tools, World Wide Web CGI programs, etc. It was written

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

More information

COMS 3101 Programming Languages: Perl. Lecture 2

COMS 3101 Programming Languages: Perl. Lecture 2 COMS 3101 Programming Languages: Perl Lecture 2 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Control Flow (continued) Input / Output Subroutines Concepts:

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Indian Institute of Technology Kharagpur PERL Part II Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 22: PERL Part II On completion, the student will be able

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

15.1 Origins and Uses of Ruby

15.1 Origins and Uses of Ruby 15.1 Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in 1996 - Use spread rapidly in Japan - Use is now growing in part because of its use in Rails - A pure object-oriented purely interpreted

More information

Scripting Languages. Diana Trandabăț

Scripting Languages. Diana Trandabăț Scripting Languages Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture What is Perl? How to install Perl? How to write Perl progams? How to run a Perl program? perl

More information

JavaScript Functions, Objects and Array

JavaScript Functions, Objects and Array JavaScript Functions, Objects and Array Defining a Function A definition starts with the word function. A name follows that must start with a letter or underscore, followed by any number of letters, digits,

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Perl. Many of these conflict with design principles of languages for teaching.

Perl. Many of these conflict with design principles of languages for teaching. Perl Perl = Practical Extraction and Report Language Developed by Larry Wall (late 80 s) as a replacement for awk. Has grown to become a replacement for awk, sed, grep, other filters, shell scripts, C

More information

[CHAPTER] 1 INTRODUCTION 1

[CHAPTER] 1 INTRODUCTION 1 FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6 Introduction to Perl Sept 24, 2007 Class Meeting 6 * Notes on Perl by Lenwood Heath, Virginia Tech 2004 Perl Background Practical Extraction and Report Language (Perl) Created by Larry Wall, mid-1980's

More information

Perl. Perl. Perl. Which Perl

Perl. Perl. Perl. Which Perl Perl Perl Perl = Practical Extraction and Report Language Developed by Larry Wall (late 80 s) as a replacement for awk. Has grown to become a replacement for awk, sed, grep, other filters, shell scripts,

More information

Babu Madhav Institute of Information Technology, UTU 2015

Babu Madhav Institute of Information Technology, UTU 2015 Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Indian Institute of Technology Kharagpur PERL Part III Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T. Kharagpur, INDIA Lecture 23: PERL Part III On completion, the student will be able

More information

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl)

Regular Expressions. Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) Regular Expressions Regular expressions are a powerful search-and-replace technique that is widely used in other environments (such as Unix and Perl) JavaScript started supporting regular expressions in

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/11/2013 Textual data processing (Perl) 1 Announcements If you did not get a PIN to enroll, contact Stephanie Meik 2 Outline Perl Basics (continued) Regular Expressions

More information

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang Chapter 1 Glossary For Introduction to Programming Using Python By Y. Daniel Liang.py Python script file extension name. assembler A software used to translate assemblylanguage programs into machine code.

More information

A Crash Course in Perl5

A Crash Course in Perl5 z e e g e e s o f t w a r e A Crash Course in Perl5 Part 1: Basics Zeegee Software Inc. http://www.zeegee.com/ Terms and Conditions These slides are Copyright 2008 by Zeegee Software Inc. They have been

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment

More information

GNU ccscript Scripting Guide IV

GNU ccscript Scripting Guide IV GNU ccscript Scripting Guide IV David Sugar GNU Telephony 2008-08-20 (The text was slightly edited in 2017.) Contents 1 Introduction 1 2 Script file layout 2 3 Statements and syntax 4 4 Loops and conditionals

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list. Arrays Perl arrays store lists of scalar values, which may be of different types. They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list. A list literal

More information

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

Programming for the Web with PHP

Programming for the Web with PHP Aptech Ltd Version 1.0 Page 1 of 11 Table of Contents Aptech Ltd Version 1.0 Page 2 of 11 Abstraction Anonymous Class Apache Arithmetic Operators Array Array Identifier arsort Function Assignment Operators

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 6/7/2012 Textual data processing (Perl) CS 5142 Cornell University 9/7/13 1 Administrative Announcements Homework 2 due Friday at 6pm. First prelim 9/27, Review on

More information

Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies. JavaScript Part I Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

BASH SHELL SCRIPT 1- Introduction to Shell

BASH SHELL SCRIPT 1- Introduction to Shell BASH SHELL SCRIPT 1- Introduction to Shell What is shell Installation of shell Shell features Bash Keywords Built-in Commands Linux Commands Specialized Navigation and History Commands Shell Aliases Bash

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

More information

CGI Programming. What is "CGI"?

CGI Programming. What is CGI? CGI Programming What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept. Almost any language can produce CGI programs even C++ (gasp!!)

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

What is PHP? [1] Figure 1 [1]

What is PHP? [1] Figure 1 [1] PHP What is PHP? [1] PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use Figure

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Perl Dbi Insert Hash Into Table >>>CLICK HERE<<<

Perl Dbi Insert Hash Into Table >>>CLICK HERE<<< Perl Dbi Insert Hash Into Table How to insert values in PostgreSQL faster than insert() value() functions? At the moment I am using DBI in Perl to connect to IQ(Sybase) then load the values into a hash,

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

3 The Building Blocks: Data Types, Literals, and Variables

3 The Building Blocks: Data Types, Literals, and Variables chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

More information

Table of Contents. Preface... xxi

Table of Contents. Preface... xxi Table of Contents Preface... xxi Chapter 1: Introduction to Python... 1 Python... 2 Features of Python... 3 Execution of a Python Program... 7 Viewing the Byte Code... 9 Flavors of Python... 10 Python

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

Perl for Biologists. Regular Expressions. Session 7. Jon Zhang. April 23, Session 7: Regular Expressions CBSU Perl for Biologists 1.

Perl for Biologists. Regular Expressions. Session 7. Jon Zhang. April 23, Session 7: Regular Expressions CBSU Perl for Biologists 1. Perl for Biologists Session 7 April 23, 2014 Regular Expressions Jon Zhang Session 7: Regular Expressions CBSU Perl for Biologists 1.1 1 Review of Session 6 Each program has three default input/output

More information

Part III Appendices 165

Part III Appendices 165 Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.

More information

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014 Q.2 a. Explain the principal components: Kernel and Shell, of the UNIX operating system. Refer Page No. 22 from Textbook b. Explain absolute and relative pathnames with the help of examples. Refer Page

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

Introduc)on to Unix and Perl programming

Introduc)on to Unix and Perl programming CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS Department of Systems Biology Technical University of Denmark Introduc)on to Unix and Perl programming EDITA KAROSIENE PhD student edita@cbs.dtu.dk www.cbs.dtu.dk

More information

IT441. Network Services Administration. Perl: File Handles

IT441. Network Services Administration. Perl: File Handles IT441 Network Services Administration Perl: File Handles Comment Blocks Perl normally treats lines beginning with a # as a comment. Get in the habit of including comments with your code. Put a comment

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013 Bash scripting Tutorial Super User Programming & Scripting 22 March 2013 Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command

More information

PERL. Pattern Extraction and Reporting Language. Example: $x = 10 $value = $x + 1 $word = "hello"

PERL. Pattern Extraction and Reporting Language. Example: $x = 10 $value = $x + 1 $word = hello PERL Pattern Extraction and Reporting Language Example: Web page serving through CGI: Perl is used extensively in serving up content when run in concert with a web-server. Talking to web sites and reporting

More information

COMS 3101 Programming Languages: Perl. Lecture 5

COMS 3101 Programming Languages: Perl. Lecture 5 COMS 3101 Programming Languages: Perl Lecture 5 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Packages & Modules Concepts: Subroutine references Symbolic

More information

COMS 3101 Programming Languages: Perl. Lecture 1

COMS 3101 Programming Languages: Perl. Lecture 1 COMS 3101 Programming Languages: Perl Lecture 1 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl What is Perl? Perl is a high level language initially developed as a scripting

More information

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi Titolo presentazione Piattaforme Software per la Rete sottotitolo BASH Scripting Milano, XX mese 20XX A.A. 2016/17, Alessandro Barenghi Outline 1) Introduction to BASH 2) Helper commands 3) Control Flow

More information

Web Scripting using PHP

Web Scripting using PHP Web Scripting using PHP Server side scripting So what is a Server Side Scripting Language? Programming language code embedded into a web page PERL PHP PYTHON ASP Different ways of scripting the Web Programming

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

PYTHON- AN INNOVATION

PYTHON- AN INNOVATION PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive

More information

We d like to hear your suggestions for improving our indexes. Send to

We d like to hear your suggestions for improving our indexes. Send  to Index [ ] (brackets) wildcard, 12 { } (curly braces) in variables, 41 ( ) (parentheses) in variables, 41 += (append) operator, 45 * (asterisk) wildcard, 12 $% automatic variable, 16 $+ automatic variable,

More information

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1 Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 POSIX character classes Some Regular Expression gotchas Regular Expression Resources Assignment 3 on Regular Expressions

More information

chapter 2 G ETTING I NFORMATION FROM A TABLE

chapter 2 G ETTING I NFORMATION FROM A TABLE chapter 2 Chapter G ETTING I NFORMATION FROM A TABLE This chapter explains the basic technique for getting the information you want from a table when you do not want to make any changes to the data and

More information

Introduction to Python Programming

Introduction to Python Programming 2 Introduction to Python Programming Objectives To understand a typical Python program-development environment. To write simple computer programs in Python. To use simple input and output statements. To

More information

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP Chapter 11 Introduction to PHP 11.1 Origin and Uses of PHP Developed by Rasmus Lerdorf in 1994 PHP is a server-side scripting language, embedded in XHTML pages PHP has good support for form processing

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information