String::Dump::Debugging - String debugging tips with String::Dump
This document describes String::Dump version 0.09.
This document is a collection of tips for debugging Unicode strings or byte strings using String::Dump.
When dumping literal strings in your code, use the utf8 pragma when Unicode strings are desired and don’t use it or disable it when byte strings are desired. The pragma may also be lexically enabled or disabled.
use utf8; { no utf8; say dump_hex('Ĝis! ☺'); # C4 9C 69 73 21 20 E2 98 BA } say dump_hex('Ĝis! ☺'); # 11C 69 73 21 20 263A
The simplest way to ensure that you’re working with Unicode strings from all of your basic sources of input is to use the utf8::all pragma. This extends the utf8 pragma to automatically convert command-line arguments provided by @ARGV, user-defined filehandles, as well as standard filehandles like STDIN, among others.
@ARGV
STDIN
To handle strings provided by other sources of input, such as from network protocols or web requests, decode the byte string to a Unicode string via Encode::decode using the source encoding name as the first argument.
use Encode qw( decode ); say dump_hex( decode('UTF-8', $string) );
Nick Patch <patch@cpan.org>
© 2011–2013 Nick Patch
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install String::Dump, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Dump
CPAN shell
perl -MCPAN -e shell install String::Dump
For more information on module installation, please visit the detailed CPAN module installation guide.