Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing an element from an AV?
by tachyon (Chancellor) on Oct 07, 2004 at 00:04 UTC | |
by Anonymous Monk on Oct 08, 2004 at 18:39 UTC | |
|
Re: Removing an element from an AV?
by ikegami (Patriarch) on Oct 06, 2004 at 22:59 UTC | |
|
Re: Removing an element from an AV?
by dave_the_m (Monsignor) on Oct 06, 2004 at 23:43 UTC | |
|
Re: Removing an element from an AV?
by Fletch (Bishop) on Oct 07, 2004 at 01:13 UTC | |
by Anonymous Monk on Oct 08, 2004 at 18:40 UTC |