PDA

View Full Version : how to detect ?


linuxis
04-07-2006, 04:28 PM
I use the following lines to store some values into a database. It works fine, and the script gives an warning if a name allready exists in the db.
Though I got the following problem, the value of the main key of the database ($go1) aint stored in uppercase or lowercase. Let's say the name 'hello' is in my database, and someone else stores 'HELLO' in it, my script wont see there is allready an hello in the db. I don't want to save the names in uppercase cause I need them later in their original state, and throwing in an extra field (name in uppercase) seems a little silly to me.

Hope you guy understand what I mean

tie(%map, 'SDBM_File', 'spiral.sdbm', O_RDWR|O_CREAT, 0666) or die "error: $!; aborting";
$error_rep = 1 if $map{$go1};
if ($error_rep<1){
$string = join("\t",$go1, $go2,$go3
$map{$go1} = $string;
print "stored";
}else{
untie %map;
print qq{Name allready exists, please choose another.<br>};
&show_html;
}
untie %map;

FishMonger
04-07-2006, 05:11 PM
Staying within your current implantation, I'd suggest making the hash keys either upper or lowercase and store their original value as part of the value, as you are currently doing.

tie(%map, 'SDBM_File', 'spiral.sdbm', O_RDWR|O_CREAT, 0666) or die "error: $!; aborting";

$error_rep = 1 if $map{lc($go1)};
if ($error_rep<1){
$map{lc($go1)} = join("\t",$go1, $go2,$go3);
print "stored";
}else{
untie %map;
print qq{Name allready exists, please choose another.<br>};
&show_html;
}
untie %map;

KevinADC
04-07-2006, 07:16 PM
First I agree with FishMonger, use the lowercase function - lc() to lowercase the data and then check it. I am curious though, this looks like a list:

$string = join("\t",$go1, $go2,$go3);

maybe you want to store that as an array in your hash instead of joining the data into a string?

$map{$go1} = [$go1,$go2,$go3];