Search in:
Login Form
Username

Password

Remember me

Forgotten your password?
No account yet? Create one
Using Perl to Convert Hyperlinks and Filenames to Lowercase

  Rating :
  
  Contributed by : The Administrator
  Member Level : Master
  Posted on : 2008-11-26



Article Index
 1.Using Perl to Convert Hyperlinks and Filenames to Lowercase
Using Perl to Convert Hyperlinks and Filenames to Lowercase
( Page 1 of 1 )
 
 

Like a lot of web developers, I'm not always that disciplined when it comes to the file naming convention I use and I sometimes end up with a situation whereby I have some files that are in lowercase, some that begin with a capital, and some that are a bit of a mixture.

One web site I maintain contains about 2000 web pages and has about 20,000 hyperlinks. As you can imagine, I had one of those sinking feelings when I was told that in order to migrate the web site to a new content management system, all the file names and hyperlinks would need to be changed to lowercase.

Whenever I am presented with a problem like this, my instinct is always to write a Perl script using one or more regular expressions to solve the problem. This particular situation was no exception.

Change a string to lowercase

The following regular expression changes all the characters in a string to lowercase. The first part of the regular expression finds a hyperlink, and the second part converts the string. (Just in case this article is not displayed correctly, there should be a single backslash in front of the 'L$1').

 

<br>1. $line =~ s/<a href="(.*?)"/<a href="L$1"/gs; <br>

 

Change a filename to lowercase

Likewise, changing a filename itself is very simple. The following two lines perform the task quite nicely:

 

1. use File::Copy; 2. move ("$name", "L$name");

 

(Again, there should be a single backslash in front of the 'L$name'.)

If you need more information on how to incorporate the above code snippets into a complete script, feel free to contact me directly.

About the Author: John Dixon is a web developer working through his own company John Dixon Technology. As well as providing web development services, John's company also provides free open source accounting software written in PHP and MySQL.

John Dixon - EzineArticles Expert Author
 


No review(s) Found !!



Specifications
  Submission Date  26-Nov-2008
  Last Update  26-Nov-2008


Member Rating Totals
  Poor  
 
 0%
  Fair  
 
 0%
  Average  
 
 0%
  Good  
 
 0%
  Excellent  
 
 0%




The following members only content has been hidden:
Member Rating Breakdown By Period and Graph of the same.

To view this content:
if you are already a registered user then login from the left panel or
click here to register - IT IS FREE