首先,创建一个文件,通过终端输入一些内容,然后,拷贝文件到另一个文件。
具体请参见如下示例:
#!/usr/bin/perl
#create file1
if (not -e "file1")
{
print "Create a new file:file1n";
system("touch file1");
open($FILE_IN,">file1")||die("Can not open file1n");
print "Begin input string into file1n";
$text_line=<STDIN>;
while(length($text_line)>1)
{
print $FILE_IN $text_line;
$text_line=<STDIN>;
}
}
open($FILE_IN,"file1")||die("Can not open file1n");
#copy file to file2
open($FILE_OUT,">file2")||die("Can not open file2");
$text_line=<$FILE_IN>;
while($text_line)
{
print $FILE_OUT $text_line;
$text_line=<$FILE_IN>;
}
close($FILE_IN);
close($FILE_OUT);