Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Trying to write a subroutine to return if file is Text or Binary

by GrandFather (Saint)
on Jun 26, 2014 at 03:21 UTC ( [id://1091292]=note: print w/replies, xml ) Need Help??


in reply to Trying to write a subroutine to return if file is Text or Binary

What do you expect to happen if both -T and -B return false as would happen for a missing file?

Are you interested in the case where both would return true as would happen for an empty file?

How robust do you want the test to be? From the documentation:

The -T and -B switches work as follows. The first block or so of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (>30%) are found, it's a -B file; otherwise it's a -T file. Also, any file containing null in the first block is considered a binary file. If -T or -B is used on a filehandle, the current IO buffer is examined rather than the first block. Both -T and -B return true on a null file, or a file at EOF when testing a filehandle. Because you have to read a file to do the -T test, on most occasions you want to use a -f against the file first, as in next unless -f $file && -T $file.
Perl is the programming world's equivalent of English
  • Comment on Re: Trying to write a subroutine to return if file is Text or Binary

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1091292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-20 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found