There are no pointers in perl, perl has "references".
Also, there are no null terminated strings. Now strings in perl (the datatype is scalar) can contain nulls (\0), they aren't null terminated (they're scalars).
If you're confused/curious about what I'm saying, read perldata, and perlref.
Now if you wish to manipulate strings, I mean, scalars in perl, you wanna use perl's built-in functions (perlfunc), and especially the "Functions for SCALARs or strings":
chomp,
chop,
chr,
crypt,
hex,
index,
lc,
lcfirst,
length,
oct,
ord,
pack,
q/STRING/,
qq/STRING/,
reverse,
rindex,
sprintf,
substr,
tr///,
uc,
ucfirst,
y/// .
Were you talking about perl? (i suspect not, it's best if you clarify)
update: aha. let's see some sourcecode.
MJD says you
can't just make shit up and expect the computer to know what you mean, retardo!
I run a Win32 PPM
repository for perl 5.6x+5.8x. I take requests.
** The Third rule of perl club is a statement of fact: pod is sexy.
|
| [reply] |
Also, there are no null terminated strings.
From pack:
The `p' type packs a pointer to a null-terminated string.
However, I'd suspect that this, or at least the unpack version, isn't what the OP is after.
--
John.
| [reply] [d/l] |
Well, actually I got a number, which is a pointer no null terminated string.
I know that Perl doesn't have pointers, but the function, returns this value, is wrote with XS glue.
And yet one thing, now I'm not sure that the function returns me pointer to null terminated string, probably it's pointer to SCALAR. Although I'm sure I got just pointer.
| [reply] |
If the function returns a 4 byte pointer then you should be able to do this:
$str = unpack "p", some_func();
If the function returns a pointer to a, known length, packed structure you can do this (where 32 is used as an example):
$struct = unpack "P32", some_func();
You will then probably need to unpack the structure to get at the members.
Referring to the particular XS API or source should tell you what is being returned.
--
John.
| [reply] [d/l] [select] |
$string = unpack "p", pack "i", $pointer;
if $pointer is a pointer to a cstring, represented as integer, then $string should contain the data.
And if it's not, enjoy the core dump ;-) | [reply] [d/l] |
Well, you can use Inline::C, like so (the library already has a type def for char * so you don't even have to mess with an SV):
use Inline C => << 'END_OF_C_CODE';
char * return_string (int pnt)
{
char *str = pnt;
return str;
}
END_OF_C_CODE
my $string = return_string($pnt);
Update: So now you think it is a point to a scalar? That would be very strange. If the C function wrapped in XS has a return type of SV* (a pointer to a scalar), XS will coerce it to a scalar in perl. Actually, the same is true for char *. The only way to return an actual address to you for a basic type (types XS already has conversions for) is through an int. I'm wondering why anyone would ever want to do this, since perl programmers have little use for addresses. | [reply] [d/l] |