in reply to Byte length

This is kinda odd.. I was looking at the Camel book in the Length area, and my copy says that Length returns the size of a scalar in bytes.???

--- snippage from the book ---

length

length EXPR

This function returns the length in bytes of the scalar value EXPR. If EXPR is omitted, the function returns the length of $_, but be careful that the next thing doesn't look like the start of an EXPR, or the tokener will get confused. When in doubt, always put in parentheses.

Do not try to use length to find the size of an array or hash. Use scalar @array for the size of an array, and scalar keys %hash for the size of a hash. (The scalar is typically dropped when redundant, which is typical.)

--- unsippage --

Just thought I would drop this into the fray, if fray there would be.

webadept.net

Replies are listed 'Best First'.
Re: Re: Byte length
by Kanji (Parson) on Mar 05, 2002 at 11:18 UTC

    You have an older Camel.

    The latest edition says ...

    length
        length EXPR
        length

    The function returns the length in characters of the scalar value EXPR.

    (Emphasis mine.)

    And then goes on to say ...

    To find the length of a string in bytes rather than characters, say:

        $blen = do { use bytes; length $string; };

    or:

        $blen = bytes::length($string); # must use bytes first

    perldoc -f length in recent Perls (5.6+) say something similar thanks to the introduction of Unicode/UTF8 support.

        --k.