Perl Open File for Write

Open File in Write mode in Perl Program


The below Perl code will just open a file and write a input text into that file and then close the file object. In this program I just open a text file "file-example.txt" and write into that file. Here open my $fh, '>', $filename or die "Fail to open and Write to File '$filename' $!"; will open file for Write
//source code write-file.pl

#!/usr/bin/perl
use strict;
use warnings;
my $filename = "file-example.txt";
open my $fh, '>', $filename or die "Fail to open and Write to File '$filename' $!";
print $fh "Report by: Foo Bar
";
print $fh "-" x 20;
print $fh "
";


Related Topic Perl Script to Store HTTP Request Response
Perl function to Get Web page Content into a File
List of Mysql Error Code and Description
How to Create a File in PHP
Updating a PHP File
Perl  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback