in reply to File Test operators, option -T
You need to test the file, not the file handle.
my $file = 'input2.txt'; print "baba baba baba baba TEXTFILE!!!\n\n\n" if -T $file; # If you still want to read it, open the file handle and enjoy open my $fh, '<', $file or die "Can't open $file to read: $!\n";
As hdb points out you can file test a file handle too. The OP was probably failing to open the file and thus getting a failure on the -T. This is another case highlighting the utility of the or die pattern
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File Test operators, option -T
by DanielSpaniel (Scribe) on Sep 10, 2013 at 13:40 UTC | |
by hdb (Monsignor) on Sep 10, 2013 at 13:44 UTC | |
by Random_Walk (Prior) on Sep 10, 2013 at 14:16 UTC |