Print text to file : File Output « File « Perl






Print text to file

    


#!usr/bin/perl

use strict;
use warnings;

print "Opening file for output:\n";
open OUTFILE, ">file.txt" or die "Can't find file.txt : $!";
print "Outputting to file.\n";
print OUTFILE "There was an old lady\n";
close OUTFILE or die "Can not close file.txt : $!";

   
    
    
    
  








Related examples in the same category

1.Print message in case of file open failure
2.Print out file line number
3.Prints the size of a file in bytes.
4.Numbering Lines in Multiple Files
5.Output file line by line
6.Output file