比较perl模块的版本(转)

比较perl模块的版本(转)[@more@]

  #!/usr/local/bin/perl -w

  ###########################################################################

  # Global definitions

  ###########################################################################

  use diagnostics;

  use strict;

  use Devel::ptkdb;

  ###########################################################################

  # Check required module

  ###########################################################################

  #

  # Here we check for --MODULES--

  #

  print " Checking perl modules ... ";

  unless (eval "require 5.005") {

  die "Sorry, you need at least Perl 5.005 ";

  }

  sub vers_cmp {

  if (@_ < 2) { die "not enough parameters for vers_cmp" }

  if (@_ > 2) { die "too many parameters for vers_cmp" }

  my ($a, $b) = @_;

  my (@A) = ($a =~ /(.|d+|[^.d]+)/g);

  my (@B) = ($b =~ /(.|d+|[^.d]+)/g);

  my ($A,$B);

  while (@A and @B) {

  $A = shift @A;

  $B = shift @B;

  if ($A eq "." and $B eq ".") {

  next;

  } elsif ( $A eq "." ) {

  return -1;

  } elsif ( $B eq "." ) {

  return 1;

  } elsif ($A =~ /^d+$/ and $B =~ /^d+$/) {

  return $A <=> $B if $A <=> $B;

  } else {

  $A = uc $A;

  $B = uc $B;

  return $A cmp $B if $A cmp $B;

  }

  }

  @A <=> @B;

  }

  # This was originally clipped from the libnet Makefile.PL, adapted here to

  # use the above vers_cmp routine for accurate version checking.

  sub have_vers {

  my ($pkg, $wanted) = @_;

  my ($msg, $vnum, $vstr);

  no strict 'refs';

  printf("Checking for %15s %-9s ", $pkg, !$wanted?'(any)':"(v$wanted)");

  eval { my $p; ($p = $pkg . ".pm") =~ s!::!/!g; require $p; };

  $vnum = ${"${pkg}::VERSION"} || ${"${pkg}::Version"} || 0;

  $vnum = -1 if $@;

  if ($vnum eq "-1") { # string compare just in case it's non-numeric

  $vstr = "not found";

  }

  elsif (vers_cmp($vnum,"0") > -1) {

  $vstr = "found v$vnum";

  }

  else {

  $vstr = "found unknown version";

  }

  my $vok = (vers_cmp($vnum,$wanted) > -1);

  print ((($vok) ? "ok: " : " "), "$vstr ");

  return $vok;

  }

  # Check versions of dependencies. 0 for version = any version acceptible

  my $modules = [

  {

  name => 'Getopt::Long',

  version => ''

  },

  {

  name => 'File::Find',

  version => ''

  },

  {

  name => 'File::Copy',

  version => ''

  },

  {

  name => 'FileHandle',

  version => ''

  },

  {

  name => 'mod_perl',

  version => ''

  }

  ];

  my %missing = ();

  foreach my $module (@{$modules}) {

  unless (have_vers($module->{name}, $module->{version})) {

  $missing{$module->{name}} = $module->{version};

  }

  }

  system("perl -v");

  system("cvs -v")

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8225414/viewspace-965600/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8225414/viewspace-965600/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值