In common cases, yes. For example, you can always be sure that ASCII is 8 bits per character (well, 7 really, but nobody stores it like that in practice). It gets a little harder with weird encodings like RAD-50, where each character actually takes 5 and a third bits per character (yup, a non-integer number of bits).

Once you start thinking in terms of Unicode, you should basically give up trying to figure out how many bytes a given character takes. Even UTF-8 encoding allows you to mark a character as having a variable-length number of bits. So unless you're working on the dark internals of handling Unicode, just use bytes (which you should probably have done even if you weren't using Unicode).

If you're intrested, see http://www.sidhe.org/~dan/blog/archives/000255.html.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated


In reply to Re: Re: Re: Re: Size of scalar in bytes by hardburn
in thread Size of scalar in bytes by Anonymous Monk

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.