读文件
use strict;
use warnings;
sub open_display_file
{
# the filename should be passed in as a parameter
my $filename = shift;
# open file to the handle <FILE>
open(FILE, $filename) || die "Could not read from $filename, program halting.";
# read the first line, and chomp off the newline
#chomp(my $firstline = <FILE>);
my $firstline = <FILE>;
print $firstline;
# read other into array
my @other = <FILE>;
print @other;
close FILE;
}
# a test to show how to call my function
&open_display_file('C:\Users\enqrrsb\Desktop\Newfolder\New folder\test.txt');
写文件
use strict;
use warnings;
sub open_write_file
{
# the filename should be passed in as a parameter
my $filename = $_[0];
# open file to the handle <FILE>
open(FILE, ">>",$filename) || die "Could not write to $filename, program halting.";
print $filename."\n";
print FILE ($_[1]."\n");
# read other into array
close FILE;
}
&open_write_file('C:\Users\enqrrsb\Desktop\Newfolder\test.txt',"rrsb");