Perl文件操作与正则表达式全解析
1. 文件操作基础
1.1 文件合并程序
在处理文件时,文件合并是一个常见需求。以下是一个文件合并程序的示例代码:
unless ( -e $first_filename && -f $first_filename && -r $first_filename )
{
die "$first_filename cannot be accessed. Does it exist?\n";
}
unless ( -e $second_filename && -f $second_filename && -r $second_filename )
{
die "$second_filename cannot be accessed. Does it exist?\n";
}
open FIRSTFILE, "$first_filename" or die "Could not open $first_filename. Aborting.\n";
open SECONDFILE, "$second_filename" or die "Could not open $second_filename. Aborting.\n";
my ( $linefromfirst, $linefromsecond );
while ( $linefromfirst = <FIRSTFILE> )
{
print $linefromfirst;
if ( !eof( SECONDFILE ) )
超级会员免费看
订阅专栏 解锁全文
109

被折叠的 条评论
为什么被折叠?



