Tom Kelliher, CS 318
Mar. 1, 2000
I'll collect programs Friday. Minimally, you need to hand-in hardcopy of your HTML form and Perl program. See Unix handouts for tips on using the printer.
Why bother with these ``details?''
Examples: no input, garbage input, can't open system files.
Standard: Is the documentation meaningful to the reader?
#!/usr/local/bin/perl -T -wTaint checks. See perlsec(1).
my $name = param("name") || "";Short-circuit evaluation.
my @record = split(/:/, $line); my @gecos = split(/,/, $record[4]); # ... if (lc($name) eq lc($record[0]) || lc($name) eq lc($gecosName[0]) || lc($name) eq lc($gecosName[1]) || lc($name) eq lc($gecosName[2])) { # ... }This is much more readable:
sub gecosMatch($$); # ... my ($uname, $pwd, $uid, $gid, $gecos, $homeDir, $shell) = split(/:/, $line); if (lc($uname) eq lc($name) || gecosMatch($name, $gecos)) { # ... } sub gecosMatch($$) { my ($name, $gecos) = @_; my ($gname, $goffice, $gwphone, $ghphone) = split(/,/, $gecos); my @names = split(/ /, $gname); foreach (@names) { if (lc($_) eq lc($name)) { return 1; } } return 0; }