Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Advanced
Feb 23, 1999

Create Hyperlinks in Perl Using a Regular Expression

When outputting HTML, it's often handy to be able to turn any URL, such as http://www.whatever.com, into a hyperlink, such as <A HREF="http://www.whatever.com">http://www.whatever.com</A>.

You can do this with a regular expression in Perl:

 
open (FILE, "myfile.txt");
while (<FILE>) {
	if (/http:/) {
		s{(http:[^\s]*)} {<A HREF="$1">$1</A>}gs;
	}
	print;
}
 
Any string in myfile.txt which contains http: will be turned into a hyperlink.
Steve Renaker
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap