Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1515580
  • 博文数量: 289
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3291
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

徐小玉的博客。

文章分类

全部博文(289)

文章存档

2023年(6)

2022年(1)

2021年(2)

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(119)

2007年(48)

2006年(20)

我的朋友

分类:

2008-03-04 10:09:22

文本拼接(10 点)
复制文件夹中每个文本文件的第一行并将其放入新文件中。

#!/usr/bin/perl -w
use strict;
# 文本拼接(10 点)
#复制文件夹中每个文本文件的第一行并将其放入新文件中
   open AIM ,">> aim/aim.txt" or die "cannot open the file"; # 打开需要写入的文件。
  my $line; # 记录文件的第一行。
  my $DIR_PATH="/odfs01/oddev3/proc_xd/myl/perl";  
  opendir DIR,${DIR_PATH} or die "cannot open!";
  my @filelist =  grep { /txt/  }  readdir DIR;  #  列出所有的txt 文件。
  my $filedir;
  foreach $filedir(@filelist){
  my $file=$filedir;
  # print $filedir."\n";
  # print "$filedir\n";
  # print "$file\n";    #  这三种方式都可以打出正确的文件名。 
   open FILE ,"< $file" or die "cannot open $file";
   $line=;
   chomp($line);
   print AIM "$line \n";
   close(FILE);
  }
阅读(1112) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~