
March 20th, 2013, 01:15 AM
|
 |
C Neophyte.
|
|
Join Date: Feb 2004
Location: Melbourne Australia
|
|
|
Storing handles in hashrefs
I'm trying to put together a class to act as a "reporting" class that I can use to sort my report files out
1. Am I reinventing the wheel?
2. How do I store a filehandle in a blessed hash in a way that works?
from this quote: "If you're storing handles in an array or hash, or in general whenever you're using any expression more complex than a bareword handle or a plain, unsubscripted scalar variable to retrieve it, you will have to use a block returning the filehandle value instead,"
What am I doing wrong?
perl Code:
Original
- perl Code |
|
|
|
use strict; use warnings; sub new { my ($class, $fileName) = @_; my $self = {}; $self-> open($fileName) if(defined $fileName); } sub printReport { my($self, $str) = @_; print {$self-> {fh }} $str; } } my($self, $fileName) = @_; open my $fh, "<", $fileName or die "could not open $fileName to write log"; $self->{fh} = $fh; } my($self) = @_; } } 1;
__________________
For one to know everything, first one must accept he knows nothing.
|