Chinaunix首页 | 论坛 | 博客
  • 博客访问: 69665
  • 博文数量: 13
  • 博客积分: 247
  • 博客等级: 二等列兵
  • 技术积分: 138
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-02 18:17
文章分类

全部博文(13)

文章存档

2015年(1)

2014年(1)

2013年(1)

2012年(2)

2011年(8)

我的朋友

分类: 系统运维

2011-08-17 10:45:53

Answers to Exercise 1 & 2:
 
Definition of Boogoo.pm:
  1. #! /usr/bin/perl -w

  2. package Boogoo;

  3. @day = qw(ark dip wap sen pop sep kir);

  4. sub number_to_day_name
  5. {
  6.         my $num = shift @_;
  7.         print STDERR "$num:not a valid day count\n" unless($num >=0 and $num <= 6);
  8.         $day[$num];
  9. }

  10. @month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep);

  11. sub number_to_month_name
  12. {
  13.         my $num = shift @_;
  14.         print STDERR "$num:not a valid month count\n" unless($num >=0 and $num <= 11);
  15.         $month[$num];
  16. }
Main Program as follows:
  1. #! /usr/bin/perl -w

  2. use strict;
  3. require 'Boogoo.pm';

  4. print STDOUT "1 to Boogoo day is: ",Boogoo::number_to_day_name(1),"\n";
  5. print STDOUT "2 to Boogoo month is: ",Boogoo::number_to_month_name(2),"\n";

  6. my @date = localtime;
  7. my ($day,$mon,$year,$wday,$mday) = (@date)[3,4,5,6];
  8. $mon = Boogoo::number_to_month_name($mon);
  9. $wday = Boogoo::number_to_day_name($wday);
  10. 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:

  1. package packageName;
  2. ...
  3. 1;

3. package use statement:

 

  1. require 'packageName.pm'
  2. ...
  3. &packageName::packageMethod;
阅读(1446) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

regansong2011-08-17 10:56:32

小松加油