Home > Archive > PERL Beginners > March 2005 > AW: How to remove everything after the last "." dot?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
AW: How to remove everything after the last "." dot?
|
|
| Bastian Angerstein 2005-03-08, 8:56 am |
| Hmmm...
use strict; use warnings;
my $a="i.like.donuts.but.only.with.tea";
$a=~s/\.\w+$//; # <---- maybe w+ not d+???
print $a, "\n";
Deutsche Telekom AG
T-Com, Technische Infrastruktur Niederlassung Überregional
Bastian Angerstein
Network Support Center -
Network Management Support
Maybachstr.57; D-70469 Stuttgart
+49 711 8939 1889 (Tel.)
+49 711 8939 6604 (Fax)
mailto:ang@nmc-m.dtag.de
http://www.t-com.de
-----Ursprüngliche Nachricht-----
Von: John Doe [mailto:security.department@tele2.ch]
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 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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Ramprasad A Padmanabhan 2005-03-08, 8:56 am |
| 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
| |
| John Doe 2005-03-08, 3:57 pm |
| Hi Bastian
> Hmmm...
Aaaarrgghh!!
> use strict; use warnings;
> my $a=3D"i.like.donuts.but.only.with.tea";
> $a=3D~s/\.\w+$//; # <---- maybe w+ not d+???
> print $a, "\n";
Yes, of course it should be \w, not \d !
I made it wrong in the test code, then corrected, then pasted the wrong=20
version...
sorry!!
To the people who suggested=20
: $a =3D~ s/\.[^.]+$//;
My thought to use \w and not [^.] was that I assumed (wrong, since the OP d=
id=20
not say that) the string consisting of dots and words only, and then I=20
considered some input sanitizing... good intent, bad result ;-)
sorry for that too.
greetings joe
>
> Deutsche Telekom AG
> T-Com, Technische Infrastruktur Niederlassung =DCberregional
> Bastian Angerstein
> Network Support Center -
> Network Management Support
> Maybachstr.57; D-70469 Stuttgart
> +49 711 8939 1889 (Tel.)
> +49 711 8939 6604 (Fax)
> mailto:ang@nmc-m.dtag.de
> http://www.t-com.de
>
> -----Urspr=FCngliche Nachricht-----
> Von: John Doe [mailto:security.department@tele2.ch]
> Gesendet: Dienstag, 8. M=E4rz 2005 11:46
> An: beginners@perl.org
> Betreff: Re: How to remove everything after the last "." dot?
>
>
> Hi
>
>
> [...]
>
> you can use a regex for that.
>
> =3D=3D=3D Documentation (from command line:)
>
>
> perldoc perlre
>
> =3D=3D=3D Code:
>
> use strict; use warnings;
> my $a=3D"i.like.donuts.but.only.with.tea";
> $a=3D~s/\.\d+$//; # <---- this does the trick
> print $a, "\n";
>
> # this prints:
> i.like.donuts.but.only.with.tea
>
> =3D=3D=3D explanation:
> see documentation ;-)
>
>
> greetings joe
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
|
|
|
|
|