I've looked and looked at your code, read the parent node and your other one and I'm not quite sure what you're actually trying to do. Still I think that you would be better off replacing the above code with the following:
# Attempt to lock only $data_dir/search.idx, if allowed if ($file_locking ne "No") { flock (SIDX, LOCK_SH) or die "Can't set lock for ". "file: $data_dir/search.idx: $!"; } # Read whole files in to arrays. This is a really bad # thing to do if the files are potentially huge. If # they are small (< 1000 lines), however this is okay. my @sidx = <SIDX>; my @sidx2 = <SIDX2>; # Closing filehandles removes the locks close (SIDX); close (SIDX2); # Make sure that the search files have the same lengths (I'm # guessing here, perhaps this isn't important to you). unless(@sidx = @sidx2) { die "Search files are of differing lengths."; } # Remove empty strings from @skeyw and @premiumkeyw @skeyw = grep {$_ ne ""} @skeyw; @premiumkeyw = grep {$_ ne ""} @premiumkeyw; # Build a big regular expression out of @skeyw and # @premiumkeyw for faster matching. my $regexp = join('|', @skeyw, @premiumkeyw); $regexp = qr/$regexp/; foreach my $line (@sidx) { my $premiumline = unshift(@sidx2); # destructive. # In the previous code you write: # $sline = $line, $premiumline; # this is the same as: # $sline = $line; # I'm going to guess that you mean the following: $sline = "$line, $premiumline"; # Do our test to see if this matches our regexp if($sline =~ /$regexp/) { # do something with search results $resultline[$icnt] = $line; $icnt++; } }
That should provide the same results as your code but faster and maybe more flexibly.

Hope this helps

jarich

Update: Fixed rather embarrassingly wrong use of != instead of ne in grep.

Also changed pop to unshift so elements come through in the same order.


In reply to Re: Re: assigning flat file dbs to arrays by jarich
in thread assigning flat file dbs to arrays by Dente

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.