Gossamer Forum
Home : Products : DBMan : Customization :

syntax for case insensitive compare

Quote Reply
syntax for case insensitive compare
can you tell me the proper syntax to make the following comparison case insensitive:

(!$per_admin) and ($in{$db_validated_field} = "Yes");

in other words, i don't care if the value is yes or Yes or YES.

thanks

Quote Reply
Re: [delicia] syntax for case insensitive compare In reply to
Try using "i". I know it works in pattern matching.

example:

((!$per_admin) && ($in{$db_validated_field} =~ /yes/i));

so maybe your could do:
(!$per_admin) and (($in{$db_validated_field} = "Yes")i);

Not sure...
Quote Reply
Re: [Watts] syntax for case insensitive compare In reply to
that didn't work but i think i understand why now. i got an error message about scalar assignment. now that i understand the statement better, it is setting the value of $in... so if i want it to be lowercase, i should just enter it that way. it isn't comparing anything, it's assigning the value.
i've gotten lots of help here so i'll share what i've done:
Code:


### two different possibilities for showing validated records
### first one below shows unvalidated records to admin only
### second one shows to anyone who is logged in
### use $admin_only flag in cfg to choose which
if ($admin_only) {
(!$per_admin) and ($in{$db_validated_field} = "Yes"); # validated records only
}
else {
($db_userid eq "default") and ($in{$db_validated_field} = "Yes"); # validated records only
}

Code:

this lets me decide for each database whether i want to show unvalidated records to just the admin or
to any user who is logged in without modifying db.cgi every time.