Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All!

Are there any examples of using 'packlist'/'unpackstring' in XS for implementing these code:

@data = unpack "C*", $script; pack "C*", @data;

Replies are listed 'Best First'.
Re: 'packlist'/'unpackstring' in XS
by BrowserUk (Patriarch) on Mar 13, 2017 at 21:48 UTC
    XS for implementing these code: @data = unpack "C*", $script;

    How much do you know about C?

    Because the "equivalent of the above code in C makes no sense. A C string is already an array of bytes.

    You don't need to pack or unpack a string(array of unsigned char), just access the elements.

    If you do not understand enough C to understand that, you should think twice about using XS; cos it'll bite you in the arse. Hard.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: 'packlist'/'unpackstring' in XS
by stevieb (Canon) on Mar 13, 2017 at 20:38 UTC

    Can you please describe in more detail what you're wanting to do here? Are you trying to pass this information into XS and wondering how to handle it there, or are you trying to retrieve data from XS and convert it within Perl?

      char *str = "Preved!!!"; char *pat = "C*"; dSP; PUTBACK; int n = unpackstring(pat, pat + 2, str, str + strlen(str), 0); SPAGAIN; AV* array2 = POPs; printf("%d, %d\n", n, av_len(array2)); =>>> 9, 44939024
      array2 is not a array pointer after POPs...
        Thank you all, I found a solution
        for (int c = n - 1; c >= 0; c--) { int a = POPi; printf("%c\n", a); }
Re: 'packlist'/'unpackstring' in XS
by AnomalousMonk (Archbishop) on Mar 13, 2017 at 21:31 UTC

    Also, could you please provide a link to the "XS" module in which the  packlist() and  unpackstring() functions or methods (as I presume them to be) are defined? Just for those of us trying to follow along at home.


    Give a man a fish:  <%-{-{-{-<