in reply to Unassociated Filehandles and Subroutines

You can use a lexically scoped scalar as your file handle and return it. This will prevent you from overwriting one open filehandle with another. I would advise always using lexically scoped scalars for file handles (it is just generally safer). See the below example:

sub myopen { my ($file, $mode, $locktype) = @_; #open the file...for the sake of brevity #I'll not include the mode logic here if (open(my $fh, "$file")){ print "Opened $file successfully.\n"; #lock the file #do whatever else needs to be done return $fh; } else { warn "Can't open: $!\n"; } }
May the Force be with you