Hello Monks,
I am seeking your wisdom for once more. I just start implementing for a first time OO programming with Perl. So I was reading online that I should use Destructors. I was also reading How do I make a destructor? and explicitly calling destructor but I can not figure it out how to use it on my modules.
I am getting the following error on my Perl module. Sample of code is provided under:
#!/usr/bin/perl use strict; use warnings; package FiLeS; sub new { my $class = shift; my $files = { dirRefFile => shift, confRefFile => shift, }; bless $files, $class; return $files; } sub getFiles { use Config::IniFiles; use Fcntl qw( :flock ); my ( $files , $dataFiles ) = @_; open my $fh , '<' , "".$dataFiles."" or die "Could not open file: ".$dataFiles." - $!\n"; flock( $fh , LOCK_SH ) or die "Could not lock '".$dataFiles."' - $!\n"; tie my %ini, 'Config::IniFiles', ( -file => "".$dataFiles."" ) or die "Error: IniFiles->new: @Config::IniFiles::errors"; close $fh or die "Could not close '".$dataFiles."' - $!\n"; return $files->{dirRefFile} = \%ini if (%ini); } sub makeDirectories { my ( $files , $hash_dir ) = @_; foreach my $dir ( sort keys %{ $hash_dir } ) { #print $dir . " {\n"; foreach my $keys ( keys %{ $hash_dir->{ $dir } } ) { #print "\t" . $keys . " \t=> "; foreach my $path ( $hash_dir->{ $dir }->{ $keys } ) { #print $path . "\n"; unless(-e $path or mkdir $path) { mkdir ($path , 0755); } } } #print "}\n"; } return $files->{ dirRefFile } = $hash_dir if ( $hash_dir ); } sub DESTROY { my $class = shift; return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; $class->{handle}->close(); } 1;
If anyone can provide some input would be great. Thanks in advance for your time and effort.
In reply to (in cleanup) Can't call method "close" on an undefined value at somePerlModule.pm line number. by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |