devxlogo

Create Hyperlinks in Perl Using a Regular Expression

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 http://www.whatever.com.

You can do this with a regular expression in Perl:

 open (FILE, "myfile.txt");while () {	if (/http:/) {		s{(http:[^s]*)} {$1}gs;	}	print;} 

Any string in myfile.txt which contains http: will be turned into a hyperlink.

devx-admin

Share the Post: