in reply to use bytes and length problem

You might try,

my $size = scalar unpack'C*', $txt;

A quick check on some content grabs from UTF websites shows a difference between the counts from that and

my $size = scalar unpack'U*', $txt;

using 5.6.1 and 5.8 (AS).

Also, the filesize shown by the OS of the same content written in binmode is same as the first above.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Replies are listed 'Best First'.
Re: Re: use bytes and length problem
by muad33b (Acolyte) on Mar 02, 2003 at 15:29 UTC

    I read up on pack/unpack, and that looked to be a good way to go, however, those are both returning "60" instead of the "208786" value I was hoping for... I'm going to continue to play with the unpack, see what I come up with... any ideas?

    Jeff

      I tested the method on this page and several of those linked from it and it gives me the correct size every time (as compared to the same data dumped to a file in binmode).

      I am pretty certain that the problem is that you are using unpack incorrectly. If you would care to post an example of the how you are using it, and a (small) sample of data that you are using it on, then I am certain that we could sort it the problem out.

      Your reply to pfaut below indicates that you are either trying to use the '/' template character, which will never give you the answers that you require, or you are mixing up the information from different parts of the pack/[and unpack documentation--which would be no surprise as it is probably some of least understandable of the perldocs.


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.

      I played around with unpack, and it appears as if the following line from the pack() perldoc (5.6 and 5.8)page is true:

      The length-item is not returned explicitly from unpack.

      Any other ideas? I know I can write this out to a file, but it seems crazy to me to have to do that just to get a proper byte count.

      Jeff