unpack
如果我想用变量前 1000 个字节尝试这个猜测子程序,这种用法是否正确?
#!/usr/bin/env perl
use warnings;
use 5.10.1;
my $var = ...;
my $part = unpack( 'b1000', $var ) ;
sub is_binary_data {
local $_ = shift;
( tr/ -~//c / length ) >= .3;
}
if ( is_binary_data( $part ) ) {
say "Binary";
}
else {
say "Text";
}