Not really surprising, since, according to perldoc,
UNIVERSAL is the base class from which all blessed references inherit
that is, the can method applies only to objects.
Would something like this do?
#! perl
use strict;
use warnings;
my $in_file = 'temp1.txt'; # this must exist
my $outfile = 'temp2.txt';
my $arrayref = [];
open(my $in, '<', $in_file) or die "Cannot open file '$in_file' for r
+eading: $!";
open(my $out, '>', $outfile) or die "Cannot open file '$outfile' for w
+riting: $!";
can_write( $in_file, $in);
can_write( $outfile, $out);
can_write('$arrayref', $arrayref);
close($in) or die "Cannot close file '$in_file': $!"
+;
close($out) or die "Cannot close file '$outfile': $!"
+;
sub can_write
{
my ($name, $fh) = @_;
my $result = eval { no warnings; print $fh '' };
printf "$name %s write\n", ($result ? 'can' : 'cannot');
}
__END__
temp1.txt cannot write
temp2.txt can write
$arrayref cannot write
Update: The CPAN module FileHandle::Fmode by Sisyphus/syphilis may also be worth investigating, although it too appears not to work with IO::All objects.
HTH,
Athanasius <°(((>< contra mundum
|