On Sep 9, Dan Muey said:
>> if -T $data ....
>> if -B $data ....
>
>I never thought of using the file test operators on variables!
I'm not so sure you can. But the docs say that -B looks for at least 30%
of the characters to be control-chars or high-bit chars. So I'd suggest:
sub is_binary_data {
local $_ = shift;
(tr/ -~//c / length) >= .3;
}
The tr/ -~//c takes the range of characters from space to tilde (32-126),
inverts it (so characters 0-31 and 127-255), and counts how many of them
are in $_. Then we divide that by the length of the string. If that's at
least .3, that means at least 30% of the string is binary data.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]