in reply to unpack "P" and a horrible death

my $long= unpack "P4", pack "L", $addr;
my $long= unpack "P4", pack "I", $addr;

Unpack wants a packed pointer, not a number. Unpack takes a string. If you give it a number, Perl will format the number into a string in decimal and pass that to unpack. Unpack will pull the first 4 characters (bytes) out and treat them like a (void *) and try to dereference that.

Update: The replying Anonymonk isn't particularly helpful and the pack docs aren't exactly clear on this point (that I saw) but I suspect that "I" gives an IV which is defined to be big enough to hold a pointer.

- tye        

Replies are listed 'Best First'.
Re: Re: unpack "P" and a horrible death (packed)
by Anonymous Monk on Mar 21, 2004 at 16:49 UTC
    That will fail when pointers are larger than 32 bits.