Section for Week 4, Tuesday, 2/2/99
1. For #3.3:
a) Go over if(defined(...))
b) undef(...) -- syntax and uses
c) Things your program should be able to cope with:
Handling missing blank last line (in file)
Take out extra space before and after field text (reverse x2
doesn't work unless you're anchoring...)
More than one blank line between records
d) Things your program should die on:
The same field is given twice in the same record
Field-name letter is invalid
Missing fields in a record
e) Given a string $_="N: Ami Fischman", how do you grab each component?
f) To take the spacing out, you don't really need two commands (though
it makes it easier).
g) join("x", $item1, $item2, $item3);
h) Common mess-ups:
chmod(MODE, FILENAME) with FILENAME containing a '>'
Assigning undef to an array field, and only getting the undef'd
warning when using the array.
2. 500 errors on HW#2 alpha.cgi:
Most common: mistyped header. Need \n's, not
to break up the
Content-type line from the rest. Need nothing before Content-type
line. CGI's must *NOT* be world readable. They should be 0755.
3. sub add_one {
return $_[0]+1; #Remember -- this is accessing @_ ! (not $_)
}
$n=<>;
print add_one($n), "\n";
4. Use my() to declare variables that are local to the function
invocation, use local() to declare var's that are local to the fcn
invocation and ALL child function calls. All other vars are global by
default.
5. Strict variable usage:
By default, Perl will allow you to declare a variable implicitly (i.e.,
merely using it for the first time causes Perl to create it). If you
want to have more careful compilation, you can "use strict" and then
declare variables using "my()":
use strict;
my($a);
my @b;
@b=<>;
$a=$#b; # Last index of @b
$c=4; # ERROR!!!
6. Review of section concepts for midterm:
(Can look up section notes on web to know all things held responsible
for on midterm).
a) Strings -- \n, etc, operators (`.', comparisons, repetition),
functions (chop, chomp)
b) RegExp's -- patterns, character classes, multipliers, memory
(parens), alternation (or), anchoring, case, operators (subst,
translation, matching)
c) Here documents, <>, , @ARGV -- uses and differences
d) Everything you did on HWs (through HW#3). Solutions to LA3 will be
posted after the due date on my web page.