Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I'm familiar with setting a binary file, but is it possible to determine wheter or not a file is binary?

Thanks

Replies are listed 'Best First'.
Re: determing a binary file
by jdporter (Paladin) on Jan 14, 2003 at 16:13 UTC
    Yes, use the  -B file test operator.

    You can read the documentation on line.

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

      The -B file test operator makes it's best guess based on the file contents which in the absence of other contextual information (extensions, metatags, etc) is the best one can do to determine filetype. In theory all files are binary files and a (usually) better question to ask is whether a file is (not) a text file and therefore whether or not you can use tools with text-based assumptions on it. The only way to fully determine this is to read the entire file and test its contents against your assumptions. In practice though most programs either rely on meta-information, user input, or so-called "magic numbers" in certain filetypes.
Re: determing a binary file
by OM_Zen (Scribe) on Jan 14, 2003 at 16:58 UTC
    Hi ,

    the  file skfhksfhk in solaris