I have a line:
i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
in this case .tea
I hav absulte no idea. I tried something like:
@parts = splite /\./, $line;
$parts[-1] = undef;
foreach $parts (@parts) {
$newline .= $parts.;
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
-70469 Stuttgart
+49 711 8939 1889 (Tel.)
+49 711 8939 6604 (Fax)
mailto:[EMAIL PROTECTED]
http://www.t-com.de
-Ursprüngliche Nachricht-
Von: John Doe [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 8. März 2005 11:46
An: beginners@perl.org
Betreff: Re: How to remove everything after the last
Bastian Angerstein [BA], on Tuesday, March 8, 2005 at 12:19 (+0100)
wrote:
BA use strict; use warnings;
BA my $a=i.like.donuts.but.only.with.tea;
BA $a=~s/\.\w+$//; # maybe w+ not d+???
BA print $a, \n;
correct code is:
use strict;
use warnings;
my $a = 'i.like.donuts.but.only.with.tea';
Bastian Angerstein wrote:
Hmmm...
use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\w+$//; # maybe w+ not d+???
Better still
$a =~s/\.[^.]+$//;
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Bastian Angerstein wrote:
I have a line:
i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
in this case .tea
Use Regex
To read the manual
perldoc perlre
Of course In your case you could simply do something like this
$line
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)
-Ursprüngliche Nachricht-
Von: John Doe [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 8. März 2005 11:46
An: beginners@perl.org
Betreff: Re: How to remove everything after the last . dot?
Hi
I have a line:
i.like.donuts.but.only.with.tea
now I want to remove everything
Bastian Angerstein wrote:
I have a line:
i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
in this case .tea
substr( $line, rindex( $line, '.' ) ) = '' if $line =~ tr/.//;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: