SPUG: better way?

Scott Blachowicz Scott.Blachowicz at seaslug.org
Tue Aug 10 15:51:17 CDT 1999


On Mon, Aug 09, 1999 at 08:21:46PM -0700, Sean Ruddy wrote:
> Better way to get just the domain from referer?
> I think this code will show my newbieness (but it works...)
> <HACK>
>  my $re = referer();
>  my $doubleslash = rindex($re,'//');
>  my $headslash = substr($re,$doubleslash+2);
>  my $domslash = index($headslash,'/');
>  print substr($headslash,0,$domslash);
> </HACK>

How about something like this:

	my ($dom) = (referer() =~ m{//([^/]+)/};
	print "$dom";

A bit of advice for those new to perl...regular expressions are really
powerful :-) (even though this simple example doesn't demonstrate
THAT)...and worth learning.

Scott.Blachowicz at seaslug.org

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list