random changes
[urisagit/CMS-Simple.git] / make_slides / output / page-0102.html
CommitLineData
9e609156 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
75package ArrayUtils;
76
77
78use Exporter;
79
80@ISA = qw( Exporter );
81
82
83use 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
91sub 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
1141;
115
116
117
118package ArrayUtils;
119
120
121use Exporter;
122
123@ISA = qw( Exporter );
124
125
126@EXPORT_OK = qw( &amp;find_max_val &amp;find_max_row );
127
128
129sub 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
149sub 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
1691;
170
171
172
173package HashDispatch;
174
175use Exporter;
176
177@ISA = qw( Exporter );
178
179@EXPORT = qw( &amp;dispatch_table );
180
181
182my $DEBUG = 1;
183print &quot;HashDispatch::DEBUG set\n&quot; if ($DEBUG);
184
185sub 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
199sub stooges {
200 my ($name, $team) = @_;
201 return &quot;$name, last name is $team-&gt;{'stooge'}-&gt;{$name}&quot;;
202}
203
204
205sub marxes {
206 my ($name, $team) = @_;
207 return &quot;$name, real name is $team-&gt;{'marx'}-&gt;{$name}&quot;;
208}
209
2101;
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
221package HashUtils;
222
223use FileHandle;
224
225use Exporter;
226
227@ISA = qw( Exporter );
228
229
230use 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
238my $DEBUG = 1;
239
240print &quot;HashUtils::DEBUG set\n&quot; if ($DEBUG);
241
242
243sub 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
2661;
267
2684 11 7
2699 15 6 2
2701 9
271
272
273use strict;
274
275use FileHandle;
276
277use ArrayUtils;
278
279
280my $filename = &quot;array-data.txt&quot;;
281
282
283my $fh = FileHandle-&gt;new();
284
285$fh-&gt;open(&quot;&lt; $filename&quot;);
286
287
288my $matrix = load_array($fh);
289
290foreach my $row (@{$matrix}) {
291 foreach my $val (@{$row}) { print &quot;$val, &quot;; }
292 print &quot;\n&quot;;
293}
294
295
296my $max_val = find_max_val($matrix);
297
298print &quot;max val is $max_val\n&quot;;
299
300
301my $max_row = find_max_row($matrix);
302
303print &quot;max row is: &quot;;
304
305foreach my $val (@{$max_row}) {
306 print &quot;$val, &quot;;
307}
308
309print &quot;\n&quot;;
310
311
312
313use strict;
314
315use FileHandle;
316
317use ArrayUtils qw( &amp;load_array &amp;find_max_val &amp;find_max_row );
318
319
320my $filename = &quot;array-data.txt&quot;;
321
322
323my $fh = FileHandle-&gt;new();
324
325$fh-&gt;open(&quot;&lt; $filename&quot;);
326
327
328my $matrix = ArrayUtils::load_array($fh);
329
330foreach my $row (@{$matrix}) {
331 foreach my $val (@{$row}) { print &quot;$val, &quot;; }
332 print &quot;\n&quot;;
333}
334
335
336my $max_val = ArrayUtils::find_max_val($matrix);
337
338print &quot;max val is $max_val\n&quot;;
339
340
341my $max_row = ArrayUtils::find_max_row($matrix);
342
343print &quot;max row is: &quot;;
344
345foreach my $val (@{$max_row}) {
346 print &quot;$val, &quot;;
347}
348
349print &quot;\n&quot;;
350
351marx groucho julius
352stooge moe howard
353stooge larry fine
354marx chico leonard
355marx harpo arthur
356stooge curly howard
357
358
359use strict;
360
361use Data::Dumper;
362
363use FileHandle;
364
365use HashUtils;
366
367
368my $filename = &quot;hash-data.txt&quot;;
369
370my $fh = FileHandle-&gt;new();
371
372$fh-&gt;open(&quot;&lt; $filename&quot;);
373
374
375my $team = load_hash($fh);
376
377print Dumper $team;
378
379
380my $table = dispatch_table();
381
382foreach 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
394use strict;
395
396use Data::Dumper;
397
398use FileHandle;
399
400use HashUtils qw( &amp;load_hash &amp;dispatch_table );
401
402
403my $filename = &quot;hash-data.txt&quot;;
404
405my $fh = FileHandle-&gt;new();
406
407$fh-&gt;open(&quot;&lt; $filename&quot;);
408
409
410my $team = HashUtils::load_hash($fh);
411
412print Dumper $team;
413
414
415my $table = HashUtils::dispatch_table();
416
417foreach 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
429use strict;
430
431use Data::Dumper;
432
433use FileHandle;
434
435use HashUtils;
436
437
438my $DEBUG = 1;
439print &quot;main::DEBUG set\n&quot; if ($DEBUG);
440
441
442my $filename = &quot;hash-data.txt&quot;;
443
444my $fh = FileHandle-&gt;new();
445
446$fh-&gt;open(&quot;&lt; $filename&quot;);
447
448
449my $team = load_hash($fh);
450
451print Dumper $team;
452
453
454my $table = dispatch_table();
455
456foreach 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