xxsr.net
当前位置:首页 >> pErl如何读入一个.txt文本中的内容,将文本里的内容... >>

pErl如何读入一个.txt文本中的内容,将文本里的内容...

%kwhash; open(LIST,"List.txt"); while(){ chomp; $kwhash{$_} = 1 ; } close LIST; open(KW, "kwList.txt"); while(){ chomp; my ($name) = split/\,/,$_; #print $name; next if (exists $kwhash{$name}); print $name; print "\n"; } close ...

如:txt中的数据(按行排列的) Steve Blenheim 101 Betty Boop 201 Igor Chevsky 301 Norma Cord 401 Jonathan DeLoach 501 Karen Evich 601 open STDIN,"date.txt" or die "cannot open for :$!"; while(@date = ){ chomp@a; }

你可以有两个方案 1) 用 dos 本身的功能 perl yourscript.pl > C:\result.txt 2) 在 perl 里做 open F, ">C:/Result.txt" or die "$! Can't prepare file!"; opendir D "D:/read" or die "$! Can't read dir!"; print F "$_$/" while ( readdir ...

open FILE, 'AA.TXT' or die; my @lines = split ( , '\n' ); my %values; foreach my $line (@lines) { if ( $line =~ /^\s*(\S+)\s*=\s*(\S+)\s*$/ ) { $values{$1} = $2; } }

还是昨天的那个程序,假设你的文件分为 1.txt 2.txt 3.txt,这个时候不要包含文件头,即所有的文件都是内容 程序修改为: #$head = ;while(){@line = split(/,/,$_);$lwfs = $line[7];$user = join('|',$line[1],$line[2],$line[3],$line[4],$li...

根据你的说明情况,我写了以下代码,经测试完全符合你的要求: 第一个TXT,执行 perl pipei.pl table_a #!/usr/bin/perl -w #pipei.pl use strict; print "ID Phone Sex Name Book\n"; while() { if(/.* male .*/) { print "$_"; } } 第二个TXT...

代码如下: #! usr/bin/perl -w use strict; use warnings; open (FILE,"./a.txt") or die "can't open file:$!"; open (NEWFILE,"./b.txt") or die "can't open file:$!"; while(my $line = ) { chomp($line); my $newline = $line =~ s/4/5/g;...

#! c:/Perl/bin/perl.exeuse Tk;use Tk::DateEntry;use Time::Local;my($sec,$min,$hour,$day,$mon,$year) = localtime();$mon++;$year += 1900;$mon1 = $mon -1;$data_now = sprintf("%04d-%01d-%02d",$year,$mon,$day);$data_no = sprintf("%0...

Perl将值写入文件,参考实例如下: 1、open( my $fh, '>', 'fruit.out' ) or die $!; print $fh $_ for @output; 2、open (OUTFILE,">>./outfile"); print OUTFILE "$a"; close(OUTFILE); 数组写入如下: #从头开始写 open(FILE,">fruit.txt"); ...

#!/usr/bin/perl -w use strict; die "perl $0 " unless(@ARGV == 1); open IN,$ARGV[0]; open OUT,">new.txt"; while(){ chomp; next unless($_=~/\+/); $_=~s/[\s \+]//g; print OUT "$_\n"; print "$_\n"; } close IN; close OUT; 上面的代码...

网站首页 | 网站地图
All rights reserved Powered by www.xxsr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com