[Perl脚本] 作品2号

1199阅读 0评论2008-06-05 mystérieux
分类:


#!/usr/bin/perl -w
# Myst Shen, June,2008.

use Fcntl;
use SDBM_File;
use Data::Dumper;


# hash

tie (%h, 'SDBM_File', 'data_file', O_RDWR|O_CREAT, 0640) || die $!;

# foreach (<>) {
#     push (@words, split);
# }
# %h = @words;


# pretty printing

print Data::Dumper->Dump([\%h], [qw(\%h)]);


# other stuff

$k0 = "A";
while (($k,$v) = each (%h)) {
    if ($k =~ "A"){
      next;
    }
    $v =~ s/0/2/g;
    $v =~ s/1/0/g;
    $v =~ s/2/1/g;
    $v0 = $h{$k0} ;

    print "$k0 ";

    for ($i=1; $i<=6; $i++) {
      if (substr ($v,-$i,1) == substr ($v0,$i-1,1)) {
        next;
      }
      else {
        print $i;
      }
    }
    print " $k";
    $k0 = $k;
    print "\n";
}


上一篇:[Perl脚本] 统计文件中的整数
下一篇:需要在路由器中作映射的端口