Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 22nd, 2000, 05:23 PM
123finder.com 123finder.com is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 73 123finder.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I know we have to use reg. expression, but any suggestions would be very helpful!
for example: <a href="link.htm"> --> <a href="http://domain.com/link.htm">

(that is just a SIMPLE form of link, take other formats of hyperlink into consideration too)



------------------
http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

------
Son

Reply With Quote
  #2  
Old August 22nd, 2000, 09:10 PM
RyanP
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
this should work, assuming that the double quote of the a href is the first double quote in the string
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$var = "<a href="link.html">";
$domain = "http://domain.com/";


$var =~ s/"/"$domain/;
// $var is now
// <a href="http://domain.com/link.html">[/code]


[This message has been edited by RyanP (edited August 22, 2000).]

Reply With Quote
  #3  
Old August 23rd, 2000, 12:11 PM
christucker2 christucker2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 81 christucker2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
You can also collapse out any ..'s in your path using:
$var =~ s![^/]*/../!!g;
Just makes it look prettier. :-)

Reply With Quote
  #4  
Old August 23rd, 2000, 12:39 PM
bvdon bvdon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: FL
Posts: 5 bvdon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
this hack would work:

$domain = "http://www.yourdomain.com/";

s/a href="/a href="$domain/;

Reply With Quote
  #5  
Old August 23rd, 2000, 12:49 PM
123finder.com 123finder.com is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 73 123finder.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I gonna try these solutions now! Thanks guys
For the last solution, "<A" need not go together with "HREF", so if you use it, in most cases, it's okay, but the error is there!!

------------------
http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

------
Son

Reply With Quote
  #6  
Old August 23rd, 2000, 01:34 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>this hack would work:
>>$domain = "http://www.yourdomain.com/";
>>s/a href="/a href="$domain/;

This would fail in many ways:

1) <A href="link.htm">
2) <a HREF="link.htm">
3) <a href ="link.htm">
4) <a href= "link.htm">

Always expect what worse things can happen. All four above are valid hyperlinks. Even the URL without quotes.

Check this out -> http://www.devshed.com/Talk/Forums/Forum5/HTML/001858.html

[This message has been edited by freebsd (edited August 23, 2000).]

Reply With Quote
  #7  
Old August 23rd, 2000, 05:04 PM
RyanP
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
chris: what are those bangs in your RE for? i've never seen them used like that

Reply With Quote
  #8  
Old August 24th, 2000, 06:11 AM
christucker2 christucker2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 81 christucker2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Ah, this is the rather tasty feature of Perl that allows you to choose your quote characters. There's no rule that says you have to use / to delimit your regular expressions (or that you have to use " to delimit an interpolated string, or ' to delimit a non-interpolated string, for that matter). You can specify your quote character as you need. So you can do:
s!find!replace!g
or even
s(find){replace}g
(Perl will allow you to use naturally paired delimiters).
For quotes, you can do:
q/my string/
for a non-interpolated string, and
qq/my string/
for an interpolated string
You don't have to use / there, you can use any non-alphanumeric, non-whitespace character.

There is a shortcut regarding /'s whereby
$var =~ /regexp/
is interpreted as
$var =~ m/regexp/

Check out the perlop manpage for more info:
perldoc perlop

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > How to parse relatives links to absolute links?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway