You can think of Perl scalars as just being strings. Using any of these strings in a place that wants a numeric value will cause the string to (try to) be interpretted as a decimal numeral. There are some details beyond this that almost never matter.

pack creates a "raw" string of bytes from multiple input values. unpack creates multiple output values from a "raw" string of bytes.

The documentation for pack and unpack are terse enough that I usually have to resort to experimentation to flush out the details even though I am very familiar with them already. "perl -de 0" and its "x" command are very useful for this.

So most of the pack formats take a string holding the decimal representation of a number, and encode that number into the "raw" format mentioned in the description of that format character, returning the "packed" string that holds the bytes of that "raw-formatted" data concatenated together.

The exceptions are the formats that mention "string" in their description along with "x", "X", and "@".

So:

> perl -de 0 [...] DB<1> x pack("C","65") 0 'A' DB<2> x unpack("C*","\0\cA A") # yields ("0","1","32","65") 0 0 1 1 2 32 3 65 DB<3> x pack("n","1") 0 "\c@\cA"
where I've put quotes around many of the "numbers" even though they aren't required just to emphasize that Perl, to a great extent, simply treats them as strings that happen to contain valid decimal representations for numbers.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Determine type of variable by tye
in thread Determine type of variable by Jrax

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.