--On Donnerstag, 23. August 2001 11:03 -0800 Michael Fowler
<[EMAIL PROTECTED]> wrote:
> Is this what you're using to verify %rec has no keys? Have you tried
> doing a dump of %rec to see what it does have?
>
> For example:
>
> use Data::Dumper;
> print Data::Dumper->([\%rec])->Terse(1)->Useqq(1)->Dump;
If I call the sub get_record in the way I described, I don't get anything
returned - the condition
if ($data[$db_key_pos] eq $key) {$found = 1;}
evaluates false, and %rec remains empty.
I haven't worked with Data::Dumper yet, so I used the clumsy workaround of
having the sub create a file and write all variables to it. From this I
could gather that $db_key_pos has the correct value, but there's something
wrong with the creation of @data, and $data[$db_key_pos] never gets the
correct value.
I suspect that the problem lies somewhere in here:
open (DB, "<$db_filname") or &cgierr("error in get_records. unable to open
db file: $db_file_name.\nReason: $!"); #opens ok
if ($db_use_flock) { flock(DB, 1); } #$db_use_flock=1
LINE: while (<DB>) { #reading in the file line by line
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
next LINE if ($restricted and ($db_userid ne
$data[$auth_user_field]));#
evaluates false
if ($data[$db_key_pos] eq $key) {# this is never true, but should be!
$db_key_pos has the correct value.
$found = 1;
for ($i = 0; $i <= $#db_cols; $i++) { # Map the array columns
to a hash.
$rec{$db_cols[$i]} = $data[$i];
}
last LINE;
}
}
close DB;
The crucial condition if ($data[$db_key_pos] eq $key) returns true if I
call the sub from a different place in the script. It does seem to depend
on whether the sub is called before (OK) or after another sub (doesn't
work), even though that other sub does not do anything with the database
file or manipulate values accessed by this sub. Very puzzling.
Sorry if I'm not providing enough information, but it is difficult for me
to figure out what information you need to understand this.
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]