in reply to Re: File Test operators, option -T
in thread File Test operators, option -T

No, I think you're wrong. You DO want to test the file handle.

With your code all you're testing is a variable value. Just because you put the name of a file in a variable doesn't make it a file - it's still just a variable.

Actually, I've tested the poster's original code, testing with both binary and text files, and it works perfectly for me, on both Linux and Windows, so I'm not quite sure how he's even getting an error.

Replies are listed 'Best First'.
Re^3: File Test operators, option -T
by hdb (Monsignor) on Sep 10, 2013 at 13:44 UTC

    Probably because the open failed if the file does not exist or is elsewhere. Testing for the success of open is a useful thing to do.

    And, -X accepts both the filehandle or the filename.

Re^3: File Test operators, option -T
by Random_Walk (Prior) on Sep 10, 2013 at 14:16 UTC

    Yes of course putting a string in a variable does not make it a file. Testing it with -T does check that it is a file, and it looks like text. As hdb points out the OPs open was probably failing so my addition of a test to open would have made that clear too.

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!