I want to remove specific elements from an array by index. I've come up with two solutions to this problem the first seems better able to deal with garbage data, the second is more efficient. Which method would you use for this problem. Something I haven't thought of?

The real data will be a list of integers corresponding to line numbers in a text file(starting at 0). The list will be returned via a cgi.pm multiple-value-enabled scolling_list().

#!/usr/bin/perl -w use strict; &delete_entry(5,3,0); &splice_entry(5,3,0); sub delete_entry{ my @removes = @_; my $datafile = "shows.data"; open(GETDEL,$datafile)or die "Cannot open $datafile: $!"; my @rows = <GETDEL>; close(GETDEL); my @fulllist; for (my $index =0;$index < @rows ;$index++) { push @fulllist,$index,$rows[$index]; } my %fullhash =(@fulllist); for (@removes) { delete $fullhash{"$_"}; } my @keeplist = (values %fullhash); print @keeplist; } sub splice_entry{ my @kills = sort @_; my $datafile = "shows.data"; open(GETSPL,$datafile)or die "Cannot open $datafile: $!"; my @rows = <GETSPL>; close(GETSPL); my $decr = 0; for(@kills){ splice(@rows,$_+$decr,1); --$decr; } print @rows; }

In reply to remove multiple indexes from an array by thunders

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.