in reply to Pointer to null terminated string

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.

Replies are listed 'Best First'.
Re: Re: Pointer to null terminated string
by jmcnamara (Monsignor) on Feb 18, 2003 at 08:20 UTC

    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.

Re: Re: Pointer to null terminated string
by Anonymous Monk on Feb 18, 2003 at 08:41 UTC
    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.

      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.

      Here you go:

      $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 ;-)