The existing file Test.txt, the content is: "123\n456"
1, Open Text test.txt
#!/usr/bin/perl
Open D, "test.txt";
D is the file handle, pointing to the open file
2, read text line by row Test.txt
#!/usr/bin/perl
Open D, "< test.txt";
while (<d>) {
Print $_;
}
Close D;
Results: 123
456
Or: Print <d>;
Results: Ibid.
<> is the fetch operator.
3, write content to Test111.txt
#!/usr/bin/perl
Open D, ">test111.txt";
Print F "Hello,world\nsee you\n";
Close D;
If Test111.txt original content, then the original content will be erased, the content of Test111.txt is
Hello,world
See you
4, append content to Test111.txt
#!/usr/bin/perl
Open D, ">>test111.txt";
Print d "Thank you\n";
Close D;
The content of Test111.txt is
Hello,world
See you
Thank
Print is equivalent to writing a command, do not lose the end of the statement ";"
Perl Language Primer--3--file read and write