initial commit
[urisagit/CMS-Simple.git] / make_slides / output / page-0101.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">Donna's Homework
22</div>
23 </H1>
24
25
26
27
28
29 <A id=next_link href="page-0102.html">Next</A>
30
31
32
33 <A id=index_link href="index.html">Index</A>
34
35
36
37
38
39
40
41<HR>
42
43
44
45 </div>
46
47 <div id="body_enclosure">
48
49
50
51
52 <UL>
53
54
55 <div class="item">
56 <LI>
57
58 <div class="item_title"></div>
59
60
61
62
63
64
65
66
67
68
69 <div class="code">
70 <font size=+1><PRE>
71
72
73# 3. CallMain1.pl
74
75package CallMain1;
76
77# This version imports the subs with explict args to use command
78
79use strict;
80use Data::Dumper;
81
82use NewArray1 qw( loadarr printarr);
83
84my $data_file= &quot;data.txt&quot;;
85
86my $AofA = loadarr($data_file);
87
88my ($aref, $hold) = printarr($AofA);
89
90print &quot;\nThe row with the largest number is: \n&quot; ;
91print Dumper $aref;
92
93print &quot;\nThe largest number is: \n&quot; ;
94print Dumper $hold;
95
96print &quot;\nProgram Complete: Array of Array's \n&quot; ;
97
98use NewHash1 qw( loadhash printhash);
99
100my $hdata_file= &quot;hdata.txt&quot;;
101
102my $HofH = loadhash($hdata_file);
103
104printhash($HofH);
105
106
107# 4. NewArray1.pm
108
109package NewArray1;
110
111use strict;
112use Data::Dumper;
113
114use base 'Exporter';
115use vars '@EXPORT_OK';
116
117@EXPORT_OK = qw( loadarr printarr );
118
119sub loadarr {
120
121 my ($fh) = @_;
122
123 open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
124
125 print &quot;\nProgram Homework1: Array of Array's \n&quot; ;
126
127 my $AofA ;
128 my $hold = 0;
129 my $aref;
130
131 while (my $line = &lt;DAT&gt;) {
132 push @{$AofA}, [split(&quot; &quot;, $line)];
133 }
134 print &quot;\nThe Array of Array's contains: \n&quot; ;
135 print Dumper @{$AofA};
136
137 return ($AofA);
138}
139
140sub printarr {
141
142 my $hold;
143 my $ele;
144 my $aref;
145
146 my ($AofA) = @_;
147
148 foreach my $Arr ( @{$AofA} ) {
149 foreach my $ele ( @{$Arr} ) {
150 if ($ele &gt; $hold) {
151 $aref = $Arr;
152 $hold = $ele;
153 }
154 }
155 }
156
157 return ($aref, $hold);
158
159}
160
161# 5. NewHash1.pm
162
163package NewHash1;
164
165use strict;
166use Data::Dumper;
167
168use base 'Exporter';
169use vars '@EXPORT_OK';
170
171@EXPORT_OK = qw( loadhash printhash );
172
173sub loadhash {
174
175my ($fh) = @_;
176
177open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
178
179print &quot;\nProgram Homework1: Two Level Hash \n\n&quot; ;
180
181my $HofH;
182
183my $team;
184my $last;
185my $first;
186
187 while (my $line = &lt;DAT&gt;) {
188 ($team, $first, $last) = split(&quot; &quot;, $line);
189 $HofH-&gt;{$team}{$first} = $last;
190 }
191
192 print Dumper %{$HofH};
193
194 return ($HofH);
195
196}
197
198sub printhash {
199
200 my ($HofH) = @_;
201
202 my %dispatch = (
203 'stooge' =&gt; \&amp;stooge,
204 'marx' =&gt; \&amp;marx,
205 'more' =&gt; \&amp;more,
206 );
207
208 foreach my $team_name (keys %{$HofH}) {
209 print &quot;\nComedy Team: $team_name\n&quot; ;
210 my $code_ref = $dispatch{ $team_name };
211 $code_ref or die &quot;Can't find $team_name in dispatch table&quot; ;
212
213 foreach my $first_name (sort keys %{ $HofH-&gt;{$team_name} } ) {
214 my $last_name = $HofH-&gt;{$team_name}-&gt;{$first_name} ;
215 print &quot;\nFirst Name : $first_name \n&quot; ;
216 $code_ref-&gt;($first_name);
217 }
218 }
219
220 sub stooge {
221 my $nameref = shift;
222 print &quot;Last Name : $HofH-&gt;{'stooge'}-&gt;{$nameref}\n&quot;;
223 }
224
225 sub marx {
226 my $nameref = shift;
227 print &quot;Last Name : $HofH-&gt;{'marx'}-&gt;{$nameref}\n&quot;;
228 }
229
230 sub more {
231 print Dumper &quot;not found&quot;;
232 }
233
234}
235
236# 3. CallMain2.pl
237
238package CallArray2;
239
240# This version imports the subs with an %EXPORT_TAGS tag
241
242use strict;
243use Data::Dumper;
244
245use NewArray2 qw( :Both);
246
247my $data_file= &quot;data.txt&quot;;
248
249my $AofA = loadarr($data_file);
250
251my ($aref, $hold) = printarr($AofA);
252
253print &quot;\nThe row with the largest number is: \n&quot; ;
254print Dumper $aref;
255
256print &quot;\nThe largest number is: \n&quot; ;
257print Dumper $hold;
258
259print &quot;\nProgram Complete: Array of Array's \n&quot; ;
260
261use NewHash2 qw( :Both);
262
263my $hdata_file= &quot;hdata.txt&quot;;
264
265my $HofH = loadhash($hdata_file);
266
267printhash($HofH);
268
269
270# 4. NewArray2.pm
271
272package NewArray2;
273
274use strict;
275use Data::Dumper;
276
277use base 'Exporter';
278use vars qw '@EXPORT_OK %EXPORT_TAGS';
279@EXPORT_OK = qw( loadarr printarr );
280%EXPORT_TAGS = ( Both =&gt;[qw(loadarr printarr)]);
281
282sub loadarr {
283
284 my ($fh) = @_;
285
286 open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
287
288 print &quot;\nProgram Homework2: Array of Array's \n&quot; ;
289
290 my $AofA ;
291 my $hold = 0;
292 my $aref;
293
294 while (my $line = &lt;DAT&gt;) {
295 push @{$AofA}, [split(&quot; &quot;, $line)];
296 }
297 print &quot;\nThe Array of Array's contains: \n&quot; ;
298 print Dumper @{$AofA};
299
300 return ($AofA);
301}
302
303sub printarr {
304
305 my $hold;
306 my $ele;
307 my $aref;
308
309 my ($AofA) = @_;
310
311 foreach my $Arr ( @{$AofA} ) {
312 foreach my $ele ( @{$Arr} ) {
313 if ($ele &gt; $hold) {
314 $aref = $Arr;
315 $hold = $ele;
316 }
317 }
318 }
319
320 return ($aref, $hold);
321
322}
323
324# 5. NewHash2.pm
325
326package NewHash2;
327
328use strict;
329use Data::Dumper;
330
331use base 'Exporter';
332use vars qw '@EXPORT_OK %EXPORT_TAGS';
333@EXPORT_OK = qw( loadhash printhash );
334%EXPORT_TAGS = ( Both =&gt;[qw(loadhash printhash)]);
335
336sub loadhash {
337
338my ($fh) = @_;
339
340open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
341
342print &quot;\nProgram Homework2: Two Level Hash \n\n&quot; ;
343
344my $HofH;
345
346my $team;
347my $last;
348my $first;
349
350 while (my $line = &lt;DAT&gt;) {
351 ($team, $first, $last) = split(&quot; &quot;, $line);
352 $HofH-&gt;{$team}{$first} = $last;
353 }
354
355 print Dumper %{$HofH};
356
357 return ($HofH);
358
359}
360
361sub printhash {
362
363 my ($HofH) = @_;
364
365 my %dispatch = (
366 'stooge' =&gt; \&amp;stooge,
367 'marx' =&gt; \&amp;marx,
368 'more' =&gt; \&amp;more,
369 );
370
371 foreach my $team_name (keys %{$HofH}) {
372 print &quot;\nComedy Team: $team_name\n&quot; ;
373 my $code_ref = $dispatch{ $team_name };
374 $code_ref or die &quot;Can't find $team_name in dispatch table&quot; ;
375
376 foreach my $first_name (sort keys %{ $HofH-&gt;{$team_name} } ) {
377 my $last_name = $HofH-&gt;{$team_name}-&gt;{$first_name} ;
378 print &quot;\nFirst Name : $first_name \n&quot; ;
379 $code_ref-&gt;($first_name);
380 }
381 }
382
383 sub stooge {
384 my $nameref = shift;
385 print &quot;Last Name : $HofH-&gt;{'stooge'}-&gt;{$nameref}\n&quot;;
386 }
387
388 sub marx {
389 my $nameref = shift;
390 print &quot;Last Name : $HofH-&gt;{'marx'}-&gt;{$nameref}\n&quot;;
391 }
392
393 sub more {
394 print Dumper &quot;not found&quot;;
395 }
396
397}
398
399# 3. CallMain3.pl
400
401package CallArray3;
402
403# This version will not import but will call the subs with Fully Qualified Names
404
405use strict;
406use Data::Dumper;
407
408use NewArray3;
409
410my $data_file= &quot;data.txt&quot;;
411
412my $AofA = NewArray3::loadarr($data_file);
413
414my ($aref, $hold) = NewArray3::printarr($AofA);
415
416print &quot;\nThe row with the largest number is: \n&quot; ;
417print Dumper $aref;
418
419print &quot;\nThe largest number is: \n&quot; ;
420print Dumper $hold;
421
422print &quot;\nProgram Complete: Array of Array's \n&quot; ;
423
424use NewHash3;
425
426my $hdata_file= &quot;hdata.txt&quot;;
427
428my $HofH = NewHash3::loadhash($hdata_file);
429
430NewHash3::printhash($HofH)
431
432
4334. NewArray3.pm --- application/octet-stream; NewArray3.pm]...
434
435package NewArray3;
436
437use strict;
438use Data::Dumper;
439
440sub loadarr {
441
442 my ($fh) = @_;
443
444 open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
445
446 print &quot;\nProgram Homework3: Array of Array's \n&quot; ;
447
448 my $AofA ;
449 my $hold = 0;
450 my $aref;
451
452 while (my $line = &lt;DAT&gt;) {
453 push @{$AofA}, [split(&quot; &quot;, $line)];
454 }
455 print &quot;\nThe Array of Array's contains: \n&quot; ;
456 print Dumper @{$AofA};
457
458 return ($AofA);
459}
460
461sub printarr {
462
463 my $hold;
464 my $ele;
465 my $aref;
466
467 my ($AofA) = @_;
468
469 foreach my $Arr ( @{$AofA} ) {
470 foreach my $ele ( @{$Arr} ) {
471 if ($ele &gt; $hold) {
472 $aref = $Arr;
473 $hold = $ele;
474 }
475 }
476 }
477
478 return ($aref, $hold);
479
480}
481
482return ('TRUE');
483
484
485# 5. NewHash3.pm
486
487package NewHash3;
488
489use strict;
490use Data::Dumper;
491
492sub loadhash {
493
494my ($fh) = @_;
495
496open DAT, &quot;$fh&quot; || die &quot;Could not open file! ($!)&quot;;
497
498print &quot;\nProgram Homework3: Two Level Hash \n\n&quot; ;
499
500my $HofH;
501
502my $team;
503my $last;
504my $first;
505
506 while (my $line = &lt;DAT&gt;) {
507 ($team, $first, $last) = split(&quot; &quot;, $line);
508 $HofH-&gt;{$team}{$first} = $last;
509 }
510
511 print Dumper %{$HofH};
512
513 return ($HofH);
514
515}
516
517sub printhash {
518
519 my ($HofH) = @_;
520
521 my %dispatch = (
522 'stooge' =&gt; \&amp;stooge,
523 'marx' =&gt; \&amp;marx,
524 'more' =&gt; \&amp;more,
525 );
526
527 foreach my $team_name (keys %{$HofH}) {
528 print &quot;\nComedy Team: $team_name\n&quot; ;
529 my $code_ref = $dispatch{ $team_name };
530 $code_ref or die &quot;Can't find $team_name in dispatch table&quot; ;
531
532 foreach my $first_name (sort keys %{ $HofH-&gt;{$team_name} } ) {
533 my $last_name = $HofH-&gt;{$team_name}-&gt;{$first_name} ;
534 print &quot;\nFirst Name : $first_name \n&quot; ;
535 $code_ref-&gt;($first_name);
536 }
537 }
538
539 sub stooge {
540 my $nameref = shift;
541 print &quot;Last Name : $HofH-&gt;{'stooge'}-&gt;{$nameref}\n&quot;;
542 }
543
544 sub marx {
545 my $nameref = shift;
546 print &quot;Last Name : $HofH-&gt;{'marx'}-&gt;{$nameref}\n&quot;;
547 }
548
549 sub more {
550 print Dumper &quot;not found&quot;;
551 }
552
553}
554return ('TRUE');
555</PRE></font>
556 </div>
557
558
559 </LI>
560 </div>
561
562
563 </UL>
564
565
566
567 </div>
568
569 <div id="footer_enclosure">
570
571
572
573<HR>
574
575
576
577
578 <A id=next_link href="page-0102.html">Next</A>
579
580
581
582 <A id=index_link href="index.html">Index</A>
583
584
585
586
587
588
589
590
591
592
593
594 </div>
595</BODY>
596
597</HTML>
598