Chinaunix首页 | 论坛 | 博客
  • 博客访问: 460129
  • 博文数量: 118
  • 博客积分: 4015
  • 博客等级: 上校
  • 技术积分: 1233
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-24 22:11
文章分类

全部博文(118)

文章存档

2013年(5)

2011年(61)

2010年(52)

分类:

2010-12-22 18:56:23

今天开始搭建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 = ; 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";

阅读(917) | 评论(0) | 转发(0) |
0

上一篇:修改U盘图标

下一篇:Shell echo -e "\033[30m"

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