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

12.26.2008
| 3209 views |
  • submit to reddit
        

#!/usr/bin/perl
#Open a file for writing and write content to it.

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

    

Comments

Snippets Manager replied on Thu, 2011/06/02 - 9: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; }