DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Perl - Writing To A File

  • submit to reddit

#Open a file for writing and write content to it.

open FILE, ">$file_name" or die $!;
print FILE $log;
close FILE;



Snippets Manager replied on Thu, 2011/06/02 - 8:31am

sub add2file { my ( $file, $message ) = @_; open my $fh, q{>>}, "$file" or croak "unable to open:$file $ERRNO"; $ret = print {$fh} $message; close $fh or croak "unable to close: $file $ERRNO"; return 1; }