Re: Length() is bits/bytes or neither

2003-08-29 Thread zsdc
david wrote: Zsdc wrote: You're right, in every case the real counting is done by the CORE::length, which only needs a little hint in $^H. The bytes::length subroutine is actually just: { BEGIN { $^H |= 8 } CORE::length $_[0] } so you don't even need to use the bytes pragma at all. TMTOWTDI I

Re: Length() is bits/bytes or neither

2003-08-28 Thread david
Zsdc wrote: > david wrote: > >> Zsdc wrote: >> >>>#!/usr/bin/perl -wl >>>use utf8; >>>sub bytes ($) { >>>use bytes; >>>length $_[0]; >>>} >>>$x = chr 123456; >>>print length $x, " chars"; >>>print bytes $x, " bytes"; >> >> you don't need to write your

Re: Length() is bits/bytes or neither

2003-08-28 Thread zsdc
david wrote: Zsdc wrote: #!/usr/bin/perl -wl use utf8; sub bytes ($) { use bytes; length $_[0]; } $x = chr 123456; print length $x, " chars"; print bytes $x, " bytes"; you don't need to write your own function to force byte semantics when you feed a utf8 string

RE: Length() is bits/bytes or neither

2003-08-28 Thread Dan Muey
Just for anyone interested :: Whilst looking at the modules some others suggested for helping find the bits/bytes of a string I ran across this simple, built in (I think - b module ??) way to find how many bits a string is: my $bit_count = unpack("%32b*",$string); I think it works pretty well

Re: Length() is bits/bytes or neither

2003-08-28 Thread david
Zsdc wrote: > In my post from 2003-08-26 Re: Length() is bits/bytes or neither > (Message-ID: <[EMAIL PROTECTED]>) I wrote some code illustrating > this issue but without any comments. Anyway, I wrote a function bytes() > which counts bytes in UTF-8 strings: > > #!/us

Re: Length() is bits/bytes or neither

2003-08-28 Thread zsdc
Sure enough, Perl counts characters, not bytes, with Unicode text. In my post from 2003-08-26 Re: Length() is bits/bytes or neither (Message-ID: <[EMAIL PROTECTED]>) I wrote some code illustrating this issue but without any comments. Anyway, I wrote a function bytes() which counts bytes in UT

RE: Length() is bits/bytes or neither

2003-08-28 Thread patrick hall
Hi, > length() returns the length in characters, which > for ASCII is also the number of bytes. To get > the bits, just multiply by 8. > If you are using a Unicode character set > instead, I'm not too sure what will be returned, > or how you can convert it to bits. Unicode can get pretty hairy,

Re: Length() is bits/bytes or neither

2003-08-26 Thread zsdc
Hanson, Rob wrote: length() returns the length in characters, which for ASCII is also the number of bytes. To get the bits, just multiply by 8. If you are using a Unicode character set instead, I'm not too sure what will be returned, or how you can convert it to bits. #!/usr/bin/perl -wl use

RE: Length() is bits/bytes or neither

2003-08-26 Thread Dan Muey
Yeah I did a test where I put the data I was using in length() into afile then did du-sh on the file. Where length() gave me 1048576 the du -sh on the file said 1.0 MB So length() returns bytes and so length() * 8 is the bits and length() / 1024 is the Kilobytes I believe. Thanks for the repli

Re: Length() is bits/bytes or neither

2003-08-26 Thread James Edward Gray II
On Tuesday, August 26, 2003, at 10:29 AM, Dan Muey wrote: I know that the number returned by the length function is the number of characters. With ascii text is that the bits or bytes also? Can't fit a character in a 1 or a 0, so I think we can safely rule out it being the bits. I would assume

RE: Length() is bits/bytes or neither

2003-08-26 Thread Hanson, Rob
length() returns the length in characters, which for ASCII is also the number of bytes. To get the bits, just multiply by 8. If you are using a Unicode character set instead, I'm not too sure what will be returned, or how you can convert it to bits. Rob -Original Message- From: Dan Muey