[clug] "Casting" in perl.

Martijn van Oosterhout kleptog at svana.org
Mon Jun 22 12:17:10 GMT 2009


On Mon, Jun 22, 2009 at 09:33:26PM +1000, Andrew Janke wrote:
> Hi all,
> 
> I know perl is supposed to be un-typed, but, let's presume I need to
> do the equivalent of this:
> 
>    unsigned long ul;
>    unsigned int ui;
> 
>    ul = sdbm_hash("blah");
>    ui = (unsigned int)ul;

What exactly are you trying to do? It would seem to be somewhat
architecture specific since the relative sizes of int and long vary
depending on the machine and compiler.

However, if the goal is to truncate the value to 32 bits, try:

$ui = $ul & 0xFFFFFFFF;

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog at svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.samba.org/archive/linux/attachments/20090622/b52a7136/attachment.bin


More information about the linux mailing list