From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 12 February 2008 20:05
To: [email protected]
Subject: URL Trimming s{} regex

> Hi, all. 
> 
> I'm having a relatively simple problem, trying to trim stuff off the
end of a URL. 
> 
> INPUT: 
> http://www.wilbert.net 
> www.worful.com/after-text.htm 
> http://www.winston.com/argle.htm 
> www.windoze.net 
> 
> DESIRED OUTPUT: 
> http://www.wilbert.net 
> www.worful.com 
> http://www.winston.com 
> www.windoze.net 
> 
> Presently I'm trying the code: 
> 
> if ($site =~ m{[^:/]/.*$}) { 
>    $site =~ s{/.+}{}; 
> } 
> 
> which gives me the output: 
> http://www.wilbert.com 
> www.worful.com 
> http: 
> www.windoze.net 
> 
> Obviously I'm doing something wrong for the third string, but I've
pulled out two or three hairs by now, trying > to fix this.  Anybody
care to take a shot? 

It can help to answer your question if you also say what you are trying
to achieve. Somebody might be able to direct you at a module that could
help with your problem. For example, the following code doesn't do
exactly what you ask, but it could be closer to what you need.

----------------------------------------------
use strict;
use warnings;

use URI::URL;

while (my $d = <DATA>) {
    chomp $d;
    my $url = URI::URL->new($d);
    $url = URI::URL->new("http://$d";) unless $url->scheme;
    print $url->scheme, "://", $url->host, "\n";
}

__DATA__
http://www.wilbert.net
www.worful.com/after-text.htm 
http://www.winston.com/argle.htm
www.windoze.net
----------------------------------------------

... but then again, maybe not. Just a thought.

HTH

-- 
Brian Raven 

=========================================
Atos Euronext Market Solutions Disclaimer
=========================================

The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

Atos Euronext Market Solutions Limited - Registered in England & Wales with 
registration no. 3962327.  Registered office address at 25 Bank Street London 
E14 5NQ United Kingdom. 
Atos Euronext Market Solutions SAS - Registered in France with registration no. 
425 100 294.  Registered office address at 6/8 Boulevard Haussmann 75009 Paris 
France.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée au 
Royaume Uni sous le numéro 3962327, dont le siège social se situe 25 Bank 
Street E14 5NQ Londres Royaume Uni.

Atos Euronext Market Solutions SAS, société par actions simplifiée, enregistré 
au registre dui commerce et des sociétés sous le numéro 425 100 294 RCS Paris 
et dont le siège social se situe 6/8 Boulevard Haussmann 75009 Paris France.
=========================================

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to