#!/usr/bin/perl package Test; use strict; sub new { my $class = shift; return bless {'destFile' => \*STDOUT}, $class; } sub open { my($self, $file) = @_; local(*F); open(F, ">$file") or die "cannot open $file for writing: $!"; $self->{destFile} = \*F; } sub output { my($self, $text) = @_; my $fh = $self->{destFile}; print "$text\n"; printf {$self->{destFile}} "$text\n"; } sub close { my $self = shift; close( $self->{destFile}); } package main; $a = Test->new; $a->open("HELLO"); $a->output("THIS IS THE LINE TO OUTPUT TO THE FILE"); $a->close; exit;