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.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to (in cleanup) Can't call method "close" on an undefined value at somePerlModule.pm line number. by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.