Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2725753
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类:

2008-01-18 16:16:04

#!/usr/bin/perl
use strict;
use Getopt::Long;
use Pod::Usage;
use File::Copy;
use Data::Dumper;
use Cwd;
use DBI;
use Encode;

package Person;
use overload '0+' => \&age, # convert type to integer
   '""' => \&name,           # convert type to string
   fallback => 1;            # make ($p - $a) possible
sub new {
   my ($this, $name, $age) = @_;
   my $class = ref($this) || $this;
   my $self = { name => $name, age => $age };
   bless $self, $class;
   return $self;
}
sub name {
   my $self = shift;
   return $self->{name};
}
sub age {
   my $self = shift;
   return $self->{age};
}
sub log10 {
 my ($n) = @_;
 print "PP10=$n\n";
 return log($n)/log(10);
}
sub log100 {
 my $n = shift;
 print "PP100=$n\n";
 return log($n)/log(10);
}
package Clock;
my $conversion={
 'seconds' => 1,
 'minutes' => 60,
 'hours' => 3600,
 'days' => 86400,
 'years' => 31557600 
};
sub new
{
 my ($type) = @_;
 my $self = {};
 $self->{time} = time();
 bless $self, $type;
}
sub get
{
 my ($self, $type) = @_;
 $type ||='seconds';
 (print ("Unkown type $type!\n"), return (undef))
            if (!defined $conversion->{$type});
 return (int($self->{time}/$conversion->{$type})); 
}
sub set
{
 my ($self, $secs) = @_;
 $self->{time} = $secs || time();
 return (1);
}
#####################################################
package main;
sub log100 {
 my $n = shift;
 print "NN100=$n\n";
 return log($n)/log(10);
}
sub log1000 {
 my($n) = @_;
 print "NN1000=$n\n";
 return log($n)/log(10);
}
my $p = Person->new("Old Brother", 20);
print $p->name, " is ", $p->age, " years old.\n";
$a = Person->new("Young Sister", 8);
print $a->name, " is ", $a->age, " years old.\n";
print $p, " is ", $p - $a, " year older than ", $a, ".\n";
print $p->log10(1000)."\n";
print $p->log100(1000)."\n";
#return::不是所想要的 参数n=
#1.30102999566398
print log100(1000)."\n";
print log1000(1000)."\n";
my $c = new Clock();
print "now time is $c->get('hours')\n";
#return::
#now time is Clock=HASH(0x250770c)->get('hours')
###########################################
my @a = ("hello", "World");
my @c = ("Jack");
unshift(@c,"hello");
print Dumper(@c)."\n";
unshift(@c,("hello","halloha"));
print Dumper(@c)."\n";
unshift(@c,@a);
print Dumper(@c)."\n";
my $first = shift(@c);
print $first."\n";
my $last = pop(@c);
print $last."\n";
###############################################
my @d=(1..9);
print ";
my @e=("a".."f");
print ";
splice(@d,2,3,@e);
print ";
#del
splice(@d,2,6);
print ";
阅读(1575) | 评论(0) | 转发(0) |
0

上一篇:Perl中数组的使用

下一篇:perl package一例

给主人留下些什么吧!~~