in reply to Re^2: delete array element from array ref
in thread delete array element from array ref

So write a function that's simple for you to use.
  • Comment on Re^3: delete array element from array ref

Replies are listed 'Best First'.
Re^4: delete array element from array ref
by blazar (Canon) on Aug 24, 2008 at 10:34 UTC

    Said all this, we have array subscripting. Perhaps one could like a more "agressive" form of subscripting that at the same time would remove the elements from the wanted array. Of course all good subscripting symbols are already gone, and moreover a similar interface would be either clumsy or risky. Perhaps, given that one suitable function to do what the OP wants could (not claiming it would be the best one in any way!) be

    sub extract { my $aref=shift; my @out=@{$aref}[@_]; @$aref=@{$aref}[grep !($_ ~~ @_) => 0..$#$aref]; @out; }

    a convenient syntax from the UI POV could be given by autobox, i.e. the following should work - but it is untested as ATM I don't have a Perl installation with that module installed and working:

    AIUI, it could even be made into a package like thus:

    Then one could say:

    use Array::Extract; my @x = 'a'..'g'; my @y = @x->extract(2,3,-8);

    Incidentally, my eternal gratitude to whoever will give me a working ppm for autobox under 5.10.*... Update: [Thu Aug 28 10:14:09 2008] problem solved, jand has my eternal gratitude!

    --
    If you can't understand the incipit, then please check the IPB Campaign.