File IO (Input and Output)

File IO is used a lot and it is very easy to do thanks to same simple Perl commands.

Writing

When you open a file for writing you use w as the second argument for the FileHandle constructor.

#!/usr/bin/perl
use FileHandle;
$MyFile = new FileHandle "temp.txt","w";
for($A = 0; $A < 10; $A++)
{
    print $MyFile "Line $A\n";
}
$MyFile->close;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License