Hi!

There is actually slight error in this code.

> $a=~s/\.\d+$//; # <---- this does the trick

This handles only one or more digits (\d stand for digits), so unless the last part of the string is a number this won't work.
Should be something like


$a=~s/\.\w+$//;  # (\w stands for word charachters)

Gretar Mar

John Doe wrote:
Hi


I have a line:
 i.like.donuts.but.only.with.tea

now I want to remove everything that follows the last "."
including the last ".".


[...]

you can use a regex for that.

=== Documentation (from command line:)


perldoc perlre

=== Code:

use strict; use warnings;
my $a="i.like.donuts.but.only.with.tea";
$a=~s/\.\d+$//; # <---- this does the trick
print $a, "\n";

# this prints: i.like.donuts.but.only.with.tea

=== explanation: see documentation ;-)


greetings joe

-- 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