1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
3 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
4 <HTML xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
8 <LINK REL="stylesheet" HREF="book.css" TYPE="text/css">
14 <div id="header_enclosure">
21 <div align="center" id="page_header_title">David Toal's Homework
27 <A id=prev_link href="page-0101.html">Prev</A>
31 <A id=next_link href="page-0103.html">Next</A>
35 <A id=index_link href="index.html">Index</A>
49 <div id="body_enclosure">
60 <div class="item_title"></div>
80 @ISA = qw( Exporter );
83 use FindArrayMax qw( &find_max_val &find_max_row );
85 @EXPORT = qw( &load_array &find_max_val &find_max_row );
86 # if this is commented out, only fully qualified calls work
88 @EXPORT_OK = qw( load_array find_max_val find_max_row );
93 print "ArrayUtils::load_array\n";
101 # print "read from file $_";
105 push @array, \@values;
123 @ISA = qw( Exporter );
126 @EXPORT_OK = qw( &find_max_val &find_max_row );
131 print "ArrayUtils::find_max_val\n";
137 foreach my $row (@{$matrix}) {
138 foreach my $val (@{$row}) {
139 $max_val = $val if ($val > $max_val);
151 print "ArrayUtils::find_max_row\n";
158 foreach my $row (@{$matrix}) {
159 foreach my $val (@{$row}) {
160 $max_row = $row, $max_val = $val if ($val > $max_val);
173 package HashDispatch;
177 @ISA = qw( Exporter );
179 @EXPORT = qw( &dispatch_table );
183 print "HashDispatch::DEBUG set\n" if ($DEBUG);
187 print "HashDispatch::dispatch_table\n" if ($DEBUG);
190 'stooge' => \&stooges ,
191 'marx' => \&marxes
200 my ($name, $team) = @_;
201 return "$name, last name is $team->{'stooge'}->{$name}";
206 my ($name, $team) = @_;
207 return "$name, real name is $team->{'marx'}->{$name}";
215 # 'stooge' => \sub { my ($name, $hash) = @_; print "stooge name is $name\n"; } ,
216 # 'marx' => \sub { my ($name, $hash) = @_; print "marx name is $name\n"; }
227 @ISA = qw( Exporter );
232 @EXPORT = qw( &load_hash &dispatch_table );
234 # @EXPORT_OK = qw( &load_hash &dispatch_table );
240 print "HashUtils::DEBUG set\n" if ($DEBUG);
245 print "HashUtils::load_hash\n" if ($DEBUG);
251 while (<$fh>) {
253 print "line is $_" if ($DEBUG);
255 my ($team, $first, $second) = split;
257 $hash{$team}->{$first} = $second;
280 my $filename = "array-data.txt";
283 my $fh = FileHandle->new();
285 $fh->open("< $filename");
288 my $matrix = load_array($fh);
290 foreach my $row (@{$matrix}) {
291 foreach my $val (@{$row}) { print "$val, "; }
292 print "\n";
296 my $max_val = find_max_val($matrix);
298 print "max val is $max_val\n";
301 my $max_row = find_max_row($matrix);
303 print "max row is: ";
305 foreach my $val (@{$max_row}) {
306 print "$val, ";
309 print "\n";
317 use ArrayUtils qw( &load_array &find_max_val &find_max_row );
320 my $filename = "array-data.txt";
323 my $fh = FileHandle->new();
325 $fh->open("< $filename");
328 my $matrix = ArrayUtils::load_array($fh);
330 foreach my $row (@{$matrix}) {
331 foreach my $val (@{$row}) { print "$val, "; }
332 print "\n";
336 my $max_val = ArrayUtils::find_max_val($matrix);
338 print "max val is $max_val\n";
341 my $max_row = ArrayUtils::find_max_row($matrix);
343 print "max row is: ";
345 foreach my $val (@{$max_row}) {
346 print "$val, ";
349 print "\n";
368 my $filename = "hash-data.txt";
370 my $fh = FileHandle->new();
372 $fh->open("< $filename");
375 my $team = load_hash($fh);
380 my $table = dispatch_table();
382 foreach my $team_name (keys(%{$team})) {
383 print "team name is $team_name\n";
385 foreach my $name (keys(%{ $team->{$team_name} })) {
386 my $result = $table->{$team_name}->($name, $team);
387 print "$result\n";
400 use HashUtils qw( &load_hash &dispatch_table );
403 my $filename = "hash-data.txt";
405 my $fh = FileHandle->new();
407 $fh->open("< $filename");
410 my $team = HashUtils::load_hash($fh);
415 my $table = HashUtils::dispatch_table();
417 foreach my $team_name (keys(%{$team})) {
418 print "team name is $team_name\n";
420 foreach my $name (keys(%{ $team->{$team_name} })) {
421 my $result = $table->{$team_name}->($name, $team);
422 print "$result\n";
439 print "main::DEBUG set\n" if ($DEBUG);
442 my $filename = "hash-data.txt";
444 my $fh = FileHandle->new();
446 $fh->open("< $filename");
449 my $team = load_hash($fh);
454 my $table = dispatch_table();
456 foreach my $team_name (keys(%{$team})) {
457 print "team name is $team_name\n";
459 foreach my $name (keys(%{ $team->{$team_name} })) {
460 my $result = $table->{$team_name}->($name, $team);
461 print "$result\n";
480 <div id="footer_enclosure">
487 <A id=prev_link href="page-0101.html">Prev</A>
491 <A id=next_link href="page-0103.html">Next</A>
495 <A id=index_link href="index.html">Index</A>