Title: Re: Array in Perl

Olivier CLERE wrote:
> Does anybody know how
> to represent an array only
> thanks to an integer?
> Is this posssible anyway?
> The address of an array
> is a scalar but not an
> integer (?)

You can take a reference to an array. This reference, when used in numeric context, is an integer. It's probably pretty useless, though.

I assume you want to use this to pass to a C interface. Thing is, even if the integer you get is the memory address of something, it'll be the address of an array of SV's (the integer can be cast to a SV*), not an array of int's or struct's or anything useful.

You may be able to get the memory address of a structure by packing it into a string and then using pack("P4711", $string), where 4711 is the length of the string. However, see `perldoc -f pack` for caveats: "You are responsible for ensuring the string is not a temporary value (which can potentially get deallocated before you get around to using the packed result)".

Your best bet is probably to write a glue interface in XS/C which translates between Perl and C worlds.

Hope this helps.

Cheers,
Philip

Reply via email to