Gossamer Forum
Home : Products : DBMan : Customization :

small and big letters by adding of new record

Quote Reply
small and big letters by adding of new record
Hello again,

First of all I want to thank you for your trouble and support.

I have one question now.

How can I make the recognition of big and small letters in my database?

I need it for my Alphabetic listing with following code:





$fieldnum = 0;
$fieldname = Title;
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) {
flock(DB, 1);
}
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
$letter = substr($fields[$fieldnum],0,1);
if (!(grep $_ eq $letter, @alphabet)) {
push (@alphabet, $letter);
}
}
close DB;

print qq|<P><CENTER>|;
$i = 65;
while ( $i < 91 ) {
if (grep $_ eq chr($i), @alphabet) {
print qq| <A HREF="$db_script_link_url&sb=1&so=ascend&$fieldname=%5E|;
print chr($i);
print qq|&re=on&view_records=1">[|;
print chr($i);
print qq|]</a>\n|;
}
else {
print "[" . chr($i) . "]";
}
++$i;
}

print qq|</CENTER></P>


|;


If I enter a word (by adding a record in the field "Title") which begins with a small letter, this word will be not indexed in the alphabetic listing.

Also I don't have this letter recognition by adding of records:

I have changed my $db_key to "Title". For example I have already the word "Access" in my database. If I enter the word "access" now, this word will be easily stored into my data base, without showing error message "Dublicate key error" to me. It seems that data base doesn't make recognition of big and small letters.

Perhaps I can make in such a way that the initial letters by adding a record are automatically converted into large letters?

Any ideas?



Thanks
Quote Reply
Re: [uhrwerk] small and big letters by adding of new record In reply to
Accordint to perlfaq4 ("Data Manipulation"), the following regular expression operation capitalizes the initial of a word:

$word =~ s/\b(\w)/\U$1/g;

Hope this helps,
kellner
Quote Reply
Re: [kellner] small and big letters by adding of new record In reply to
Hi,

But I didn't really understand where should I enter this line:$word =~ s/\b(\w)/\U$1/g;

I have tried to enter it in sub html_record_form. But it doesn't work. :(

Can you explain me it more exactly?

I would be very grateful to you.



thanks in advance...
Quote Reply
Re: [uhrwerk] small and big letters by adding of new record In reply to
$word was meant to represent the variable which holds the word you want to capitalize. Just an example, not the actual code. I thought this was obvious.

So, for example, when you want to have a newly added record in field "Name" capitalized before it gets added to the database, go to sub add_record in db.cgi and add in the beginning:

$in{Name} =~ s/\b(\w)/\U$1/g;

When you only want words *displayed* with capitalized initial, but not changed in the database, you could go to html_record and add:

$rec{Name} =~ s/\b(\w)/\U$1/g;

somewhere after the first line "%rec = @_;".

It all depends on what you want to do. That's for you to decide.
kellner
Quote Reply
Re: [kellner] small and big letters by adding of new record In reply to
Thank you....it works!!!!!Smile