You may have had fun, but maintenance programmers or those seeking inspiration or enlightenment would not. Your code contains the same errors that choroba describes, it adds a needlessly nested named sub, a bogus close statement and a nonsensical call to writeOut. The following more conventional code would have served as a simpler and better example:
#!/usr/bin/perl use strict; use warnings; package MyFilehandler; sub openForRead { my ($class, $file) = @_; my $self = bless {file => $file}, $class; open $self->{fh}, '<', $file or die "could not open '$self->{file} +': $!"; return $self; } sub DESTROY { my ($self) = @_; close $self->{fh}; } sub writeOut { my ($self) = @_; my $fh = $self->{fh}; print <$fh>; } package main; my $testfh = MyFilehandler->openForRead('somefile'); $testfh->writeOut();
In reply to Re^2: Yet another Can't locate object method question
by GrandFather
in thread Yet another Can't locate object method question
by nemesdani
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |