Perl write to file

In this article let’s discuss about Perl write to file. Let’s go through the following methods without any delay 🙂

In order to write to a file you need to open a file. Using open command you can open the file. If the file is not present it will create a new file for us.

open(my $fh, '>', 'report.txt');
print $fh "My first report generated by perl\n";
close $fh;
# no package/library needed/dependant

Hope the above methods works for you. Happy Learning and get back to us Anytime.

Realted Posts : Perl replace substring