Answers to Exercise 1 & 2:
Definition of Boogoo.pm:
- #! /usr/bin/perl -w
- package Boogoo;
- @day = qw(ark dip wap sen pop sep kir);
- sub number_to_day_name
- {
- my $num = shift @_;
- print STDERR "$num:not a valid day count\n" unless($num >=0 and $num <= 6);
- $day[$num];
- }
- @month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep);
- sub number_to_month_name
- {
- my $num = shift @_;
- print STDERR "$num:not a valid month count\n" unless($num >=0 and $num <= 11);
- $month[$num];
- }
Main Program as follows:
- #! /usr/bin/perl -w
- use strict;
- require 'Boogoo.pm';
- print STDOUT "1 to Boogoo day is: ",Boogoo::number_to_day_name(1),"\n";
- print STDOUT "2 to Boogoo month is: ",Boogoo::number_to_month_name(2),"\n";
- my @date = localtime;
- my ($day,$mon,$year,$wday,$mday) = (@date)[3,4,5,6];
- $mon = Boogoo::number_to_month_name($mon);
- $wday = Boogoo::number_to_day_name($wday);
- print STDOUT "Today is ",$wday,", ",$mon," $day,",$year + 1900,"\n";
总结:
1.notice that,when calling a package method using "&",need to put "&" before package name.
2.package declaration:
- package packageName;
- ...
- 1;
3. package use statement:
- require 'packageName.pm'
- ...
- &packageName::packageMethod;
阅读(1446) | 评论(1) | 转发(0) |