On Wednesday 02 February 2005 22:39, Chris Schults wrote:
> Howdy all. I'm a newbie with a newbie question. I assume that I'm in the
> right place.

Yes, thie does sound consistent. ;-)

> I need to update some code a developer programmed for my organization.
>
> The purpose of the code is really basic. It simply prints: $title.
> $subtitle.
>
> However, some of my titles and subtitles end with punctuation ("?", "!",
> ".", "..."). Thus, I end up with: Am I a title that ends with punctuation?.
> Do-oh!.
>
> So, I need to revise the code so that it first checks each string to see if
> it ends with a punctuation character. If it does, don't add the period. If
> not, do add the period. Note: the string should be kept as is.
>
> I believe the key is a regular expression of some sort, but I can't seem to
> figure it out.

You're definitely on the right track using regular expressions - for starters, 
you might want to take a look at

  perldoc perlre
  perldoc perlretut

You probably want a construction like

  if ($variable_that_might_end_in_punctuation !~ /<regular expression>/) {
    # add the period
  }

This matches your string against the regular expression that you need to put 
between the slashes (without the less-than/greater-than characters) and 
returns true if the string does *not* match the regular expression (the 
opposite operator would be 
  $variable =~ /<regexp>/
which returns true if the regexp matches.

Given the description of your problem, you might be interested in character 
classes - they are described in perlretut (section "Using character 
classes").

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to