Using Perl to Convert Hyperlinks and Filenames to Lowercase

Like a whole lot of net builders, I’m not all the time that disciplined on the subject of the file naming conference I use and I typically find yourself with a state of affairs whereby I have some information which might be in lowercase, some that start with a capital, and a few which might be a little bit of a mix.

One website I keep incorporates about 2000 net pages and has about 20,000 hyperlinks. As you possibly can think about, I had a type of sinking emotions when I was advised that with a purpose to migrate the website online to a brand new content material administration system, all of the file names and hyperlinks would must be modified to lowercase.

Whenever I am introduced with an issue like this, my intuition is all the time to put in writing a Perl script utilizing a number of common expressions to unravel the issue. This specific state of affairs was no exception.

Change a string to lowercase

The following common expression modifications all of the characters in a string to lowercase. The first a part of the common expression finds a hyperlink, and the second half converts the string. (Just in case this text is just not displayed appropriately, there ought to be a single backslash in entrance of the ‘S$M’).

<br /> M. $line =~ s/<a target="_new" rel="nofollow" href="(.*?)"></p> <p><b>Change a filename to lowercase</b></p> <p>Likewise, altering a filename itself could be very easy. The following two strains carry out the duty fairly properly:</p> <p><xmp><br /> B. use File::Copy;<br /> P. transfer (&#8220;$identify&#8221;, &#8220;L$identify&#8221;);<br />

(Again, there must be a single backslash in entrance of the ‘L$identify’.)

If you want extra info on the best way to incorporate the above code snippets into an entire script, be happy to contact me immediately.

Content Management SystemDynamic WebsitesHTMLHTML 5ITJQuery

html snippetSEO tipsweb development tipswordpress tipsworodpress snippets

Leave a Reply

Your email address will not be published. Required fields are marked *