文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Perl 程序 计算各个 字段的长度

Perl 程序 计算各个 字段的长度

时间:2010-12-22  来源:neobilly

今天开始搭建MySQL数据库了,现在手里已经有每条记录了,字段间以'\t'分隔开,建表的时候需要确定个字段的长度,于是,写了下面的脚本,打印各字段的最大长度
源代码(maxlength.pl)如下:
  1 #!/usr/bin/perl
  2 my $in = $ARGV[0];
  3 die "no input file" if(!defined($in));
  4 open(RH,$in) or die "Cannot read $in:$!";
  5 my @lines = <RH>; chomp @lines;
  6 close RH or die "Cannot close $in:$!";
  7 my @maxlengths;
  8 for(my $i = 0; $i < @lines; $i++){
  9     my @fields = split(/\t/,$lines[$i]);
 10     for(my $j = 0; $j < @fields;$j ++){
 11         if(length($fields[$j]) > $maxlengths[$j]){
 12             $maxlengths[$j] = length($fields[$j]);
 13         }
 14     }
 15 }
 16 print join('--',@maxlengths),"\n";

相关阅读 更多 +
排行榜 更多 +
ooxe官方版下载

ooxe官方版下载

金融理财 下载
ooxe

ooxe

金融理财 下载
OXE交易app安卓版下载

OXE交易app安卓版下载

金融理财 下载