initial commit
[urisagit/CMS-Simple.git] / make_slides / output / page-0102.html
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">
5 <HEAD>
6
7 <TITLE></TITLE>
8 <LINK REL="stylesheet" HREF="book.css" TYPE="text/css">
9
10 </HEAD>
11
12
13 <BODY id="" >
14         <div id="header_enclosure">
15
16                 
17         
18
19                 
20                 <H1>
21                 <div align="center" id="page_header_title">David Toal's Homework
22 </div>
23                 </H1>
24                 
25
26         
27                 <A id=prev_link href="page-0101.html">Prev</A>
28         
29
30         
31                 <A id=next_link href="page-0103.html">Next</A>
32         
33
34         
35                 <A id=index_link href="index.html">Index</A>
36         
37
38         
39
40
41         
42
43 <HR>
44
45         
46
47         </div>
48
49         <div id="body_enclosure">
50
51                 
52         
53
54         <UL>
55
56         
57                 <div class="item">
58                 <LI>
59                 
60                         <div class="item_title"></div>
61                 
62
63                 
64
65                 
66
67                 
68
69
70                 
71                         <div class="code">
72                                 <font size=+1><PRE>
73
74
75 package ArrayUtils;
76
77
78 use Exporter;
79
80 @ISA = qw( Exporter );
81
82
83 use FindArrayMax qw( &amp;find_max_val  &amp;find_max_row );
84
85 @EXPORT = qw( &amp;load_array  &amp;find_max_val  &amp;find_max_row );
86 # if this is commented out, only fully qualified calls work
87
88 @EXPORT_OK = qw( load_array  find_max_val  find_max_row );
89
90
91 sub load_array {
92
93   print &quot;ArrayUtils::load_array\n&quot;;
94
95   my $fh = shift;
96
97   my @array;
98
99   while (&lt;$fh&gt;) {
100
101     # print &quot;read from file $_&quot;;
102
103     my @values = split;
104
105     push @array, \@values;
106  
107   }
108
109   return \@array;
110
111 }
112
113
114 1;
115
116
117
118 package ArrayUtils;
119
120
121 use Exporter;
122
123 @ISA = qw( Exporter );
124
125
126 @EXPORT_OK = qw( &amp;find_max_val  &amp;find_max_row );
127
128
129 sub find_max_val {
130
131   print &quot;ArrayUtils::find_max_val\n&quot;;
132
133   my $matrix = shift;
134
135   my $max_val;
136
137   foreach my $row (@{$matrix}) {
138     foreach my $val (@{$row}) {
139       $max_val = $val if ($val &gt; $max_val);
140     }
141   }
142
143   return $max_val;
144
145 }
146
147
148
149 sub find_max_row {
150
151   print &quot;ArrayUtils::find_max_row\n&quot;;
152
153   my $matrix = shift;
154
155   my $max_row;
156   my $max_val;
157
158   foreach my $row (@{$matrix}) {
159     foreach my $val (@{$row}) {
160       $max_row = $row, $max_val = $val if ($val &gt; $max_val);
161     }
162   }
163
164   return $max_row;
165
166 }
167
168
169 1;
170
171
172
173 package HashDispatch;
174
175 use Exporter;
176
177 @ISA = qw( Exporter );
178
179 @EXPORT = qw( &amp;dispatch_table );
180
181
182 my $DEBUG = 1;
183 print &quot;HashDispatch::DEBUG set\n&quot; if ($DEBUG);
184
185 sub dispatch_table {
186
187   print &quot;HashDispatch::dispatch_table\n&quot; if ($DEBUG);
188
189   my $dispatch = {
190      'stooge' =&gt; \&amp;stooges ,
191      'marx'   =&gt; \&amp;marxes
192   };
193
194   return $dispatch;
195
196 }
197
198
199 sub stooges {
200   my ($name, $team) = @_;
201   return &quot;$name, last name is $team-&gt;{'stooge'}-&gt;{$name}&quot;;
202 }
203
204
205 sub marxes {
206   my ($name, $team) = @_;
207   return &quot;$name, real name is $team-&gt;{'marx'}-&gt;{$name}&quot;;
208 }
209
210 1;
211
212
213
214   # my $dispatch = {
215   #    'stooge' =&gt; \sub { my ($name, $hash) = @_; print &quot;stooge name is $name\n&quot;; } ,
216   #    'marx'   =&gt; \sub { my ($name, $hash) = @_; print &quot;marx name is $name\n&quot;; }
217   # };
218
219
220
221 package HashUtils;
222
223 use FileHandle;
224
225 use Exporter;
226
227 @ISA = qw( Exporter );
228
229
230 use HashDispatch;
231
232 @EXPORT = qw( &amp;load_hash  &amp;dispatch_table );
233
234 # @EXPORT_OK = qw( &amp;load_hash  &amp;dispatch_table );
235
236
237
238 my $DEBUG = 1;
239
240 print &quot;HashUtils::DEBUG set\n&quot; if ($DEBUG);
241
242
243 sub load_hash {
244
245   print &quot;HashUtils::load_hash\n&quot; if ($DEBUG);
246
247   my $fh = shift;
248
249   my %hash;
250
251   while (&lt;$fh&gt;) {
252
253     print &quot;line is $_&quot; if ($DEBUG);
254
255     my ($team, $first, $second) = split;
256
257     $hash{$team}-&gt;{$first} = $second;
258
259   }
260
261   return \%hash;
262
263 }
264
265
266 1;
267
268 4 11 7
269 9 15 6 2
270 1 9
271
272
273 use strict;
274
275 use FileHandle;
276
277 use ArrayUtils;
278
279
280 my $filename = &quot;array-data.txt&quot;;
281
282
283 my $fh = FileHandle-&gt;new();
284
285 $fh-&gt;open(&quot;&lt; $filename&quot;);
286
287
288 my $matrix = load_array($fh);
289
290 foreach my $row (@{$matrix}) {
291   foreach my $val (@{$row}) { print &quot;$val, &quot;; }
292   print &quot;\n&quot;;
293 }
294
295
296 my $max_val = find_max_val($matrix);
297
298 print &quot;max val is $max_val\n&quot;;
299
300
301 my $max_row = find_max_row($matrix);
302
303 print &quot;max row is: &quot;;
304
305 foreach my $val (@{$max_row}) {
306   print &quot;$val, &quot;;
307 }
308
309 print &quot;\n&quot;;
310
311
312
313 use strict;
314
315 use FileHandle;
316
317 use ArrayUtils qw( &amp;load_array  &amp;find_max_val  &amp;find_max_row );
318
319
320 my $filename = &quot;array-data.txt&quot;;
321
322
323 my $fh = FileHandle-&gt;new();
324
325 $fh-&gt;open(&quot;&lt; $filename&quot;);
326
327
328 my $matrix = ArrayUtils::load_array($fh);
329
330 foreach my $row (@{$matrix}) {
331   foreach my $val (@{$row}) { print &quot;$val, &quot;; }
332   print &quot;\n&quot;;
333 }
334
335
336 my $max_val = ArrayUtils::find_max_val($matrix);
337
338 print &quot;max val is $max_val\n&quot;;
339
340
341 my $max_row = ArrayUtils::find_max_row($matrix);
342
343 print &quot;max row is: &quot;;
344
345 foreach my $val (@{$max_row}) {
346   print &quot;$val, &quot;;
347 }
348
349 print &quot;\n&quot;;
350
351 marx groucho julius
352 stooge moe howard
353 stooge larry fine
354 marx chico leonard
355 marx harpo arthur
356 stooge curly howard
357
358
359 use strict;
360
361 use Data::Dumper;
362
363 use FileHandle;
364
365 use HashUtils;
366
367
368 my $filename = &quot;hash-data.txt&quot;;
369
370 my $fh = FileHandle-&gt;new();
371
372 $fh-&gt;open(&quot;&lt; $filename&quot;);
373
374
375 my $team = load_hash($fh);
376
377 print Dumper $team;
378
379
380 my $table = dispatch_table();
381
382 foreach my $team_name (keys(%{$team})) {
383   print &quot;team name is $team_name\n&quot;;
384
385   foreach my $name (keys(%{ $team-&gt;{$team_name} })) {
386     my $result = $table-&gt;{$team_name}-&gt;($name, $team);
387     print &quot;$result\n&quot;;
388   }
389
390 }
391
392
393
394 use strict;
395
396 use Data::Dumper;
397
398 use FileHandle;
399
400 use HashUtils qw( &amp;load_hash  &amp;dispatch_table );
401
402
403 my $filename = &quot;hash-data.txt&quot;;
404
405 my $fh = FileHandle-&gt;new();
406
407 $fh-&gt;open(&quot;&lt; $filename&quot;);
408
409
410 my $team = HashUtils::load_hash($fh);
411
412 print Dumper $team;
413
414
415 my $table = HashUtils::dispatch_table();
416
417 foreach my $team_name (keys(%{$team})) {
418   print &quot;team name is $team_name\n&quot;;
419
420   foreach my $name (keys(%{ $team-&gt;{$team_name} })) {
421     my $result = $table-&gt;{$team_name}-&gt;($name, $team);
422     print &quot;$result\n&quot;;
423   }
424
425 }
426
427
428
429 use strict;
430
431 use Data::Dumper;
432
433 use FileHandle;
434
435 use HashUtils;
436
437
438 my $DEBUG = 1;
439 print &quot;main::DEBUG set\n&quot; if ($DEBUG);
440
441
442 my $filename = &quot;hash-data.txt&quot;;
443
444 my $fh = FileHandle-&gt;new();
445
446 $fh-&gt;open(&quot;&lt; $filename&quot;);
447
448
449 my $team = load_hash($fh);
450
451 print Dumper $team;
452
453
454 my $table = dispatch_table();
455
456 foreach my $team_name (keys(%{$team})) {
457   print &quot;team name is $team_name\n&quot;;
458
459   foreach my $name (keys(%{ $team-&gt;{$team_name} })) {
460     my $result = $table-&gt;{$team_name}-&gt;($name, $team);
461     print &quot;$result\n&quot;;
462   }
463
464 }
465
466 </PRE></font>
467                         </div>
468                 
469
470                 </LI>
471                 </div>
472         
473
474         </UL>
475
476
477
478         </div>
479
480         <div id="footer_enclosure">
481                 
482
483         
484 <HR>
485
486         
487                 <A id=prev_link href="page-0101.html">Prev</A>
488         
489
490         
491                 <A id=next_link href="page-0103.html">Next</A>
492         
493
494         
495                 <A id=index_link href="index.html">Index</A>
496         
497
498         
499
500
501         
502
503         
504
505
506
507         </div>
508 </BODY>
509
510 </HTML>
511