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
replies everyone! Dan > -Original Message- > From: Dan Muey > Sent: Tuesday, August 26, 2003 10:30 AM > To: [EMAIL PROTECTED] > Subject: Length() is bits/bytes or neither > > > I know that the number returned by the length function is the > number of characters.

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
: Dan Muey [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 26, 2003 11:30 AM To: [EMAIL PROTECTED] Subject: Length() is bits/bytes or neither 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? If not is there a fun

Length() is bits/bytes or neither

2003-08-26 Thread Dan Muey
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? If not is there a function similar to length() that tells you the bits or bytes of a string or a way to figure that with the return value of length? TIA Dan -- To