i have to honestly say, i didnt read the entire problem, but i see a line in
your code which you probably don't want:

 while (<FILE>) {
 my @line = split /\|/, <FILE>;

the while thing puts the line in $_
you are then discarding that line, and reading hte *next* line in that file
and feeding that to split.

this causes you to effectively skip one line each time.

perhaps that solves your mystery?

regards,

Jos


----- Original Message -----
From: "Birgit Kellner" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, September 22, 2001 6:22 PM
Subject: searching file for presence of ALL values of a hash when the hash
key is the position of the value on the file's line


> #Task: I'm reading in a database file line by line. Each line contains one
> record, whose fields are separated by "|".
> #I have a hash with several key/value-pairs.
> #The key is the position of the field on the line, the value is the
> expression
> #that should be present in that position. I want to retrieve all lines in
> the file which contain ALL
> #values together, and it is possible that this is true for more than one
> line.
> #This is the code I have so far:
>
> use strict;
> my (@hits, $key);
> my %hash = ('0' => 'miller', '1' => '32', '2' => 'copenhagen');
> open (FILE, "<test.txt") or die ("can't open: $!");
> my $found = 0;
> while (<FILE>) {
> my @line = split /\|/, <FILE>;
> foreach $key (keys %hash) {
> if ($line[$key] eq "$hash{$key}") {
> $found++;
> if ($found = scalar keys %hash) {
> push (@hits, @line); last;
> }
> else {
> next;
> }
> }#end if
> }#end foreach
> }#end while
> foreach my $hit (@hits) {print "HIT: $hit\n";}
>
> # the problem is that this works if test.txt reads:
> #somestuff|15|copenhagen
> #miller|32|copenhagen
> #kellner|15|vienna
> #miller|32|copenhagen
> # With this file, I correctly get two hits back.
> #However, it doesn't work for:
> #miller|32|copenhagen
> #somestuff|15|copenhagen
> #kellner|15|vienna
> #miller|32|copenhagen
> # Neither does it work for:
> #somestuff|15|copenhagen
> #kellner|15|vienna
> #miller|32|copenhagen
> #miller|32|copenhagen
> #For these two files, I only get one hit back. Any clues?
> # Birgit Kellner
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to