Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Greetings again,
Okay so maybe the hash in not in order but I have a few questions about your current approach.
Since you are allowing for multiple selections in your scrolling_list
print $q->scrolling_list('htapes99',[@H99tapes],[$H99tapes[0]],10,-mul +tiple=>'true',my %attributes);
if the user selected four elements from random places in the list then the first five values are clipped from the list, four times. Not the elements the user selected.
my $tape_count = scalar @tape_imports; foreach (@tape_imports) { splice (@H99tapes,0,$tape_count,@H99tapes) }
It seems like each time through your foreach (hypothetically four times) you clip the the elements in @H99tapes from 0 to $tape_count (in this case 4) so five elements are removed from the beginning of the array. Also by replacing the missing values with the entire list again you are increasing the size of your list almost exponentially, at least by a factor of scalar(@H99tapes) - (scalar(@tape_imports) + 1). In a test I ran with your code and four random values the resulting size of @H99tapes was 15252! Its starting size was 957.
The impetus behind my hash suggestion was that you could use the map to remove those elements with the same value as those the user selected rather than trying to manipulate the list based on positional index, however looking at your code a hash is not in order, yet the logic still is. So it seems like you would want to remove those values stored in @tape_imports from the @H99tapes list. In that case you could use the first example from my previous post.
my @H99tapes =('H02043' .. 'H02999'); #...form stuff here my @tape_imports = $q->param(htapes99); #clean out all the values in @tape_imports from @H99tapes @H99tapes = do{ my @a = @H99tapes; #make a local copy of our list #now @a gets fed element by element into our map block #and its value is assigned to $_ map { #local copy of incoming value for map. We do this #because grep also assigns its values to $_ so #in order to not confuse things we assign it to a #locally scoped var $v my $v = $_; #check if this value is in the forbidden #list @tape_imports or not. We anchor the #regexp to avoid partial matches from other #values like '90' matching against '1905'. (!grep /^$v$/, @tape_imports) ? $v : (); } @a; };
Does that makes sense? Or am I not getting it? I think splice might not be what you are looking for since it deals with postional indexing rather than element values. You would need to know what postions in your @H99tapes array the user selected elements are at in order to accurately splice them out. Since map returns a list we can just re-write the @H99tapes array with a grep call to filter out unwanted values, regardless of position.

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

In reply to Re^3: popping, shifting or splicing an array??? by injunjoel
in thread popping, shifting or splicing an array??? by drock

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (9)
    As of 2019-11-15 10:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (82 votes). Check out past polls.

      Notices?