coldguy was right, you cannot use a reference as a hash key. Also, I don't think you can use unlink on a filehandle ... just a filename. If you want to stay the same path, I would just expand your structure a bit:
#!/usr/local/bin/perl use strict; my $files = [ { name => 'file1.txt', fh => undef, unlink => 1 }, { name => 'file2.txt', fh => undef, unlink => 1 }, { name => 'file3.txt', fh => undef, unlink => 1 }, ]; foreach my $file ( @$files ) { open( $file->{fh}, '>', $file->{name} ) or quit( $files, "Cannot open $file->{name}: $!" ); } quit( $files, "CloseUnlinkTest.pl finished" ); sub quit { my( $files, $message ) = @_; foreach my $file ( @$files ) { close( $file->{fh} ) if $file->{fh}; unlink( $file->{name} ) if $file->{unlink}; } }
In reply to Re: Trouble Passing File Handles
by derby
in thread Trouble Passing File Handles
by Photius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |