广州明生堂生物科技有限公司


perl读写文件代码实例

网络编程 perl读写文件代码实例 06-21

#mode operand create truncate
#read <
#write > yes yes
#append >> yes

Case 1: Throw an exception if you cannot open the file:

use strict;

use warnings;

 

my $filename = 'data.txt';

open(my $fh, '<:encoding(UTF-8)', $filename)

or die "Could not open file '$filename' with the error $!";

 

while (my $row = <$fh>) {

chomp $row;

print "$rown";

}

close($fh);
  

Case 2: Give a warning if you cannot open the file, but keep running:

use strict;

use warnings;

 

my $filename = 'data.txt';

if (open(my $fh, '<:encoding(UTF-8)', $filename)) {

while (my $row = <$fh>) {

chomp $row;

print "$rown";

}

close($fh);

} else {

warn "Could not open file '$filename' $!";

}
  

Case 3: Read one file into array

use strict;

use warnings;

 

my $filename = 'data.txt';

open (FILEIN, "<", $filename) 

or die "Could not open file '$filename' with the error $!";

my @FileContents = <FILEIN>;

for my $l (@FileContents){

print "$ln";

}

close FILEIN;
  

end

perl中使用signal(信号)实例
使用signal,能让你的程序功能更丰富。要在Linux下列出所有的signal,利用kill-l即可。下面是我机器上的输出(后面还有到64的没列出来):xuyang@xuyang-deskt

python urllib中的编码处理示例
importurllibdata='丽江'printdata丽江data'xe4xb8xbdxe6xb1x9f'urllib.quote(data)'%E4%B8%BD%E6%B1%9F'那我们想转回去呢?urllib.unquote('%E4%B8%BD%E6%B1%9F')'xe4xb8xbdxe6xb1x9f'pri

Perl中的10个操作日期和时间的CPAN模块介绍
能够操控日期和时间对于大多数编程语言来说是基本的能力,Perl也不例外。但是在碰到与时间相关的更加复杂的处理时,Perl自带的功能常常就显得力不


编辑:广州明生堂生物科技有限公司

标签:丽江,时间,日期,功能,也不