in reply to (Ovid) Re: Using File Reference
in thread Using File Reference
This program will create the HELLO file in the current directory but it WILL NOT print the output line to it. ?????? IS there anything wrong here.#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: (Ovid) Re: Using File Reference
by danboo (Beadle) on Apr 05, 2002 at 20:29 UTC |