Here is one way to do it simply using av_shift and av_push iterating over the AV* It is probably not the best or fastest way. In general it is not recommended to operate on an array while iterating over it, although it can be done in certain circumstances. An alternative method, that removes the shift overhead is simply to create a new temp AV*, iterate over your original AV* extracting the values and doing the comparison and push into your new AV*. Don't forget to destroy your excess AV* or you will leak. See perlguts for all the handy macros you have available.....

use Inline 'C'; my @ary = ('aa'..'az', 'aj'); my $rc = remove_str( \@ary, 'aj' ); print"$rc\n@ary\n"; __END__ __C__ int remove_str( SV* av_ref, SV* remove ) { AV* terms; SV* element; I32 num, i; STRLEN len; int retval = 0; terms = (AV *)SvRV(av_ref); num = av_len(terms); for( i=0; i<=num; i++ ) { element = av_shift(terms); if( strcmp( SvPV(element,len), SvPV(remove,len) ) ) av_push(terms, element); else retval++; } return retval; }

cheers

tachyon


In reply to Re: Removing an element from an AV? by tachyon
in thread 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.