How to append records to a file using PERL

Hi All,

Great Forum and Great help. Keep up the good work.

My question is what is the command and it's syntax to append a record to an output file using PERL. Please provide the command syntax.

In regular shell you can use the '>>' to append.

Basically, I am creating a small report and I want to write the records out (Each record) to an output file, which I can then email.

Thanks
Nurani

Also in Perl '>>' is used for appending stuff to a file:

#!/usr/local/bin/perl

use strict;
use warnings;

my $line1='ABCDEFGH';
my $line2='09876543';

open(OUT,">>mydata.dat") or die "Error: $!\n";
print OUT $line1 . "\n" . $line2 . "\n";
close(OUT);

Test run / script demonstration:

$ cat mydata.dat
abcdefghi
123456789
$ ./append.pl
$ cat mydata.dat
abcdefghi
123456789
ABCDEFGH
09876543
$ 

---------- Post updated at 03:32 ---------- Previous update was at 03:26 ----------

Of course, if you already have a working Perl script which produces proper output, you could redirect the output to another file from the shell without modifying your existing Perl script, e.g. ./yourscript.pl >> filetoappend