They're unprintable, so you can't see them by definition. You could replace them with some form of representation. For example,
Untested.sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; }
Update: Tested. Fixed bugs.
Update: Here's an alternative representation (for charsets based on ASCII):
sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([\x01-\x1F])/'^' . chr(ord('@')+ord($1))/ s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; }
The first program outputs
test\x{1}\x{2}\x{1D}test
and the second outputs
test^A^B^]test
for the result of the Perl expression
"test".chr(1).chr(2).chr(29)."test"
In reply to Re: I want to know exactly what comes through a socket
by ikegami
in thread I want to know exactly what comes through a socket
by ivanatora
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |