I upvoted your post for its pack-related links and  H example.

However, there was one feature of the example that made my buggy-sense tingle: assignment to  $, to achieve desired output formatting. (I realize you may have done this merely to support a quick-and-dirty example, but I think it's a best-practice to always exemplify Best Practices in example code.)

Of course,  $, is a Perl special variable (see perlvar). These variables are all package-globals, and as such should IMHO always be carefully local-ized within the narrowest possible scope when they are changed. E.g.:

c:\@Work\Perl\monks>perl -le "use strict; use warnings; use charnames qw(:full); ;; my $string = qq{123456\N{FS}}; { local $, = q( ); print unpack '(H2)*', $string; } " 31 32 33 34 35 36 1c
Even so, localized scoping is dynamic, not lexical, so such a change propagates to all subsidiary scopes, such as that in an invoked subroutine. This can lead to some very perplexing bugs.

I think an even better practice is to format an output string (or do most other things) in a way that avoids scoping issues altogether:

c:\@Work\Perl\monks>perl -le "use strict; use warnings; use charnames qw(:full); ;; my $string = qq{123456\N{FS}}; print join ' ', unpack '(H2)*', $string; " 31 32 33 34 35 36 1c
join does just what you want and has absolutely no effect outside of the statement in which it appears. Control of scope gives you great power, but with great power comes great capability to blow your entire leg off!


Give a man a fish:  <%-{-{-{-<


In reply to Re^2: concatenate a non-printable character onto an ascii string and inspect the content by AnomalousMonk
in thread concatenate a non-printable character onto an ascii string and inspect the content by holandes777

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.