in reply to Re: Searching data file
in thread Searching data file

Actually, I think there's a slight problem with this design. The markup structure makes it clear that it is meant to handle refs with multiple authors, and when there is such a ref entry, your "process_record" sub will only return the first author -- then this single author will be the basis for testing if the record matches the given search. So if the name being searched for happens to be the second author in a record, that record won't be returned.

You would need the hash element for "author" be a reference to an array, and then search over the elements of that array, which makes it a lot more complicated than if you were reading a whole <ref>...</ref> element at each iteration (by setting $/ as I suggested above), and looking for $search anywhere within the  <authlist> element.

Replies are listed 'Best First'.
Re: Re: Re: Searching data file
by Roger (Parson) on Nov 03, 2003 at 02:44 UTC
    Yes you are right, there is a problem that my code does not pick out multiple authors. I have omitted multiple authors for being lazy.

    Fixing the code is simple though, just modify the code slightly to read multiple authors (same as multiple keys).
    my @author = $rec =~ m/<key>\s*([^<]*)(?=<)/g; $col{author} = \@author;
    And how to store the returned hash structure by the subroutine needs to be revised too since there can be multiple authors. That should be a simple exercise.

      If you wanted to use the hash again in another program (ie. save the data as a hash in a file for future use) -- how do you get the data to be 'loaded' in the new program so that you could use the statement below? $myinfo = $records{'Sydney'}{'Title'}; I looked on the web and everyone is using the 'eval' function but there are no good examples.