I’m trying to print a recursive data structure in Perl for debugging purposes. Hash of hashes of arrays of hashes, that kind of thing …
Some of its basic data elements are printable strings, so I’m printing those. Unfortunately, some of the basic data elements are binary (think content from image files). They screw up my debug output with gibberish.
How would I detect which is which, so I can avoid printing the binary as if it was a string?
(I am aware of Data::Dumper. My question is not about whether or not I should replicate that functionality, but about how to distinguish between text and binary strings.)
perlrecharclass defines these character classes:
So you could match on a character that does not have the Unicode property (note capital
P), e.g.:I suspect what you really want is to detect control characters, which screw up the terminal (note lower-case
p):