Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by DrHyde (Prior)
on Jun 26, 2014 at 10:25 UTC ( #1091327=note: print w/replies, xml ) Need Help??


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

I was playing around with this and expecting to post something clever about how -B doesn't mean binary - according to the documentation it means "not ASCII", which ain't the same as binary. However ...

$ perl -v This is perl, v5.8.8 $ cat foo
文本
(this is apparently Chinese for "text") $ perl -e 'print -T "foo"' 1 $ perl -e 'print -B "foo"' $

So even as far back as 5.8.8 it DTRT, although the documentation is wrong.

Update: sorry for the bad formatting - perlmonks doesn't like me cutting and pasting funny foreign characters into a <code> block.

Replies are listed 'Best First'.
Re^2: Trying to write a subroutine to return if file is Text or Binary
by csorrentini (Acolyte) on Jun 26, 2014 at 17:05 UTC
    Thank you all for the quick replies. After posting this I realized how I was completely overlooking the fact that it is still considered text even putting zeroes and ones in the file. Essentially all I wanted was it to return text file if sending something like a .txt doc or something similar and return binary file IF a binary file was sent to it and it works like a charm. Again, thanks all
      After posting I went to p5p and asked "WTF?". Apparently there is work going on (whether it'll be accepted and whether it'll be in 5.22 or not remains to be seen) to improve -T and -B. See here and here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2019-04-21 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (111 votes). Check out past polls.

    Notices?