The entire line is being from a UTF-8 file that was correctly read by using open(my $in, '<:utf8', $file)

You've already "unpacked" the bytes (= 8 bit chunks), which contain integers, into UTF-8 characters after doing that.

unpack() is for reading "raw" bytes when you know ahead of time how those raw bytes are laid out in the file. A raw byte is one that has not undergone a translation (:utf8 applies a translation). First, you need to realize that a file contains only integers. A computer can only store numbers--not characters. So characters are represented by integer codes. But if you encounter the integer 120 in a file, how do you know whether that should be the id of a customer(i.e. the actual integer) or the ascii code for the letter 'x'?

A byte is an 8 bit chunk of memory that is used to store an integer. unpack() allows you to tell perl exactly what each byte in a file should represent. For instance, you can tell perl that the first 4 bytes represent one integer, the next byte is an integer which represents the ascii code for a character, followed by an undetermined number of bytes which is the UTF-8 integer code for a character, the next 8 bytes after that represent one integer, etc.

A file contains only integers, and each integer occupies 1 byte(=8 bits). Furthermore, you can tell perl how to interpret the integers it encounters. If you want to read raw bytes from a file so that you can tell perl exactly how to interpret each byte, you can do that.


In reply to Re: perlpacktut "packing text" example and Unicode by 7stud
in thread perlpacktut "packing text" example and Unicode by glasswalk3r

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.