Gossamer Forum
Home : Products : DBMan : Customization :

getting rid of last character in field record

Quote Reply
getting rid of last character in field record
Back to dbman after a few months, all my perl has vanished from my brain. So excuse me if the following is an all too basic question.

I would like to have the script check the last character in a field value and perform actions accordingly.

Examples: If the value of $rec{'booktitle'} is "who stole my horse?", where the last character is a question-mark, then the script should NOT print a full-stop after printing $rec{'booktitle'}. If the last character is some alphanumeric character, then it should print a full-stop.

In more general terms, I'd like to check whether the last character in an entry is an interpunction.

Any help greatly appreciated, as always,

cheers,

birgit


kellner
Quote Reply
Re: getting rid of last character in field record In reply to
In html.pl in the sub-routine html_record, you could do something like the following:

my $full_stop;
if ($rec{'booktitle'} =~ /[\!\?]$/) { $full_stop = ''; }
else { $full_stop = '.'; }

... Some HTML ...
Book title: $rec{'booktitle'}$full_stop
... More HTML ...


What this does, is look at the last character of $rec{'booktitle'}, if it's a "?" or "!" then leave the full stop blank, otherwise make it a ".".

If you have any other characters that you don't want "full-stopped", then you can add them inbetween the square brackets. (make sure you escape it though)

Hope this helps

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: getting rid of last character in field record In reply to
thanks a lot. I had gotten as far as using a matching operator and regular expressions, but couldn't think of the proper variable use.

kellner
Quote Reply
Re: getting rid of last character in field record In reply to
one more thing, though:
the above code works fine if what I want to do is print out specific characters AFTER the booktitle depending on its last character.
now what to do if the task is NOT TO PRINT the last character IN the booktitle on certain conditions? to be precise: I don't want to delete the character in the actual database entry, but I just want dbman not to print a final question-mark if a certain other field has a value.

kellner
Quote Reply
Re: getting rid of last character in field record In reply to
How about:
if (($rec{'booktitle'} =~ /[\!\?]$/) && ($rec{'field_name'} eq 'condition')) { $rec{'booktitle'} =~ s/[\!\?]$//; }

What this will do is, if the title has a "?" or "!" and "field_name" equals "condition", then get rid of the punctuation at the end of the title.

Is that kinda what you were after?

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: getting rid of last character in field record In reply to
yep, thanks again. Should have known that swapping was what I should have been after :-)

kellner