Hi everyone. I have a question about the Perl API.

I have a C function that manipulates an AV. Basically, it needs to push SV *'s containing unique strings into the AV, and then periodically remove an SV from the list. To remove an SV, I'd like to, um, grep it, kind of like this:

$scalar_to_remove = 'unique_string'; @array = grep({$_ ne $scalar_to_remove} @array);

How exactly can I accomplish this from C? Do I need to use perl_call_pv(sv_2mortal(newSVpvn("grep", 4))) and then do some stack magic to satisfy grep's calling conventions, then some more stack magic to copy back the resulting array? If so, is there any other simpler way to remove a scalar from an AV? A C equivalent of splice() maybe? I looked into av_delete(), but it's recent as of 5.6, which makes me suspect that it behaves just like delete() does when called on an array (undefs the scalar but doesn't remove it from the list; doesn't shrink the list).

Thanks in advance.


In reply to Removing an element from an AV? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.