If you add these lines at the start, you will find lots of useful messages:

use warnings; # needs 5.6.0 or newer, # $^W = 1; # for older use strict;

The $search_for variable is only ever set to "Jan" because you assign it that way in my $search_for = $_[0];. I think you want to do something like this:

sub search_database { my $database = shift; my @search_for = map {qr/$_/i} @_; my @results; open(DB, $database) or die 'Error opening file: ', $!; while (<DB>) { my @record = split /::/; push @results, [@record] if grep { $record[5] # or whichever =~ /$_/i; # /o taken care of by qr } @search_for; } close DB or die $!; \@results; }
That removes the $search_field conditions which are badly set up and are confusing the issue. The search now is restricted to just the field where a date should appear, avoiding confusion with "Janice", "Martin", and "taproot". The function now returns a reference to the @results array instead of writing to one in a larger scope. The arguments are changed to include the name of the $database file. The caller gets all fields, and can index the desired ones.

After Compline,
Zaxo


In reply to Re: Need help with toy array. THX by Zaxo
in thread Need help with toy array. THX by cal

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.