SPUG: better way?

David Bitseff dbitsef at uswest.com
Tue Aug 10 18:48:43 CDT 1999


Okay, that is the second time this week I've replied to the wrong
address in this group.  I think I've got it figured out now.  Sorry
about that Ken.


-----------------------------------------------------------------------


It's also good to use the regex or URI::URL because while the
rindex/substr/index might run slightly faster, it won't correctly
match all URI.   Consider this one:

http://somewhere.somemachine.net/A=181217/?http://somewhereelse.there.com

The rindex would return the position of '//' right before
'somwhereelse'.  Of course, if you don't use URLs like this is doesn't
really matter.

>>>>> On 1  Aug MCMXCIX XV:II:XV, Ken McGlothlen writes:

Ken> Sean Ruddy <sean at DigiDot.com> writes:
Ken> | Better way to get just the domain from referer?
Ken> | I think this code will show my newbieness (but it works...)
Ken> | <HACK>
Ken> |  my $re = referer();
Ken> |  my $doubleslash = rindex($re,'//');
Ken> |  my $headslash = substr($re,$doubleslash+2);
Ken> |  my $domslash = index($headslash,'/');
Ken> |  print substr($headslash,0,$domslash);
Ken> | </HACK>

Ken> Yes, that works.  But you might be better off with a regex:

Ken> 	sub urldomain {
Ken> 	    $_ = shift;
Ken> 	    m|^http://([^/]+)|;
Ken> 	    return( $1 );
Ken> 	}

Ken> Then you can call it with something like

Ken> 	my $dom = &urldomain( $re );


-- 
David Bitseff
U S WEST Creative Services
dbitsef at uswest.com         
(206) 346-9279

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